Android Player


We recommend using KSYMediaPlayer Android SDK for pushing RTMP stream as it's oepn source and enhanced streaming SDK. In this section, we will introduce how to integrate with KSY Android Player SDK.

Preparation

Please download souce code of latest release from KSY github.

https://github.com/ksvc/KSYMediaPlayer_Android

Once you have downloaded the source code, please import the source code to your app via android studio.

Integration Sample Code

1. Initialization
public class VideoPlayerActivity extends Activity{
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.your_layout);

            mVideoView = (KSYTextureView) findViewById(R.id.ksy_textureview);
            //Set listener
            mVideoView.setOnBufferingUpdateListener(mOnBufferingUpdateListener);
            mVideoView.setOnCompletionListener(mOnCompletionListener);
            mVideoView.setOnPreparedListener(mOnPreparedListener);
            mVideoView.setOnInfoListener(mOnInfoListener);
            mVideoView.setOnVideoSizeChangedListener(mOnVideoSizeChangeListener);
            mVideoView.setOnErrorListener(mOnErrorListener);
            mVideoView.setOnSeekCompleteListener(mOnSeekCompletedListener);
            //Set play parameters
            mVideoView.setBufferTimeMax(2.0f);
            mVideoView.setTimeout(5, 30);
            //......
            //(Other parameter Settings)
            //......
            //Set the playback address and prepare
            mVideoView.setDataSource("http://your_address.flv");
            mVideoView.prepareAsync();
        }
}
2. Start Playing
private IMediaPlayer.OnPreparedListener mOnPreparedListener = new IMediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(IMediaPlayer mp) {
            if(mVideoView != null) {
                // Set the video scaling mode, which is the cropping mode                mVideoView.setVideoScalingMode(KSYMediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
                // Start playing video                
    mVideoView.start();
            }
        }
    }
3. Stop Playing
 private View.OnClickListener mStopButton = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(mVideoView != null){
                mVideoView.stop();
            }
        }
    }
4. Play New Stream
if (mVideoView != null){
        //Video is currently playing, please stop the current play
        mVideoView.stop();
        //Reset the play
        mVideoView.reset();
        //Reset the playback parameters
        mVideoView.setBufferTimeMax(2.0f);
        mVideoView.setTimeout(5, 30);
        mVideoView.setRotateDegree(90);
        //......
        //(Other parameter Settings)
        //......
        //Set the new play address
        mVideoView.setDataSource("http://your_new_address.mp4");
        mVideoView.prepareAsync();
    }
5. Front and Background Switching
@Override
    protected void onPause() {
        super.onPause();
        if (mVideoView != null) {
            // mAudioBackgroundPlay is true to indicate that audio is still played after switching to the background.
            mVideoView.runInBackground(mAudioBackgroundPlay);
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (mVideoView != null) {
            mVideoView.runInForeground();
        }
    }
6. Release Playback
private void videoPlayEnd() {
        if (mVideoView != null) {
            //Release player
            mVideoView.release();
        }
    }

Recommend using bitrate adaption for mobile app streaming push.

7. Live Streaming Delay Control
We recomend using dynamic buffer to balance deplay and stuck for live streaming play if network instable.

- When the value set to 0.5f, the live broadcast pursuit function will be turned off, and the delay between the anchor and the audience will be large
- When using HLS mode for live broadcasting, the threshold should be set to a higher value or set to 0.5f to turn off the chase function, otherwise it is easy to trigger the chase and cause stuck

Set interface: setBufferTimeMax(float bufferTimeSecond)

© 2018 Conversant Solutions Pte Ltd. All rights reserved.            Updated 2021-12-09 06:49:11

results matching ""

    No results matching ""