MySoha Player SDK

A Flutter plugin supports playing and streaming videos in a variety of media formats.

Features

  • x Secure player
  • x Support FLV, DASH, HLS, MP3, MP4
  • x Support live, VOD
  • x Play, pause, seek, smooth change quality (streaming HLS, DASH)
  • x Mute, unmute, change audio volume
  • x Get event player, duration

Supported platforms

  • Android

Set up

Firstly, you need to have valid appKey, secretKey, playerId corresponse to your applicationId in build gradle file to initialize player.

Implements the OnConfigListener interface to listen the response from SDK about authentication process, then call the getInitializeSDKState function:

    final player_sdk = PlayerSdk();
    player_sdk.getInitializeSDKState(appKey, secretKey, playerId, onConfigListener);

Make sure to listen all callbacks from the OnConfigListener interface.

  • If init failed, you can log the error message, handle it and try again
  • If init successfully, you now can use our player with your source video
    void onPrepare();
    
    void onInitFailed(String errorType, String message);
     
    void onInitializing();
    
    void onInitSuccessfully();

After initialize player successfully, you can create instance of PlayerController to set up player config and NativePlayerView to set up player view. Implements OnPlayerListener and OnPreparePlayer interfaces to listen events from SDK. For example:

    // setup player
    final playerController = PlayerController();
    
    playerController.createNewInstancePlayer(onPreparePlayer);
    playerController.enableLiveOffControl(true);
    playerController.setTimeOffsetAdvertDefault(10);
    playerController.setOnPlayerListener(onPlayerListener);
    playerController.setOnPreparePlayer(onPreparePlayer);
    playerController.setStartAutoPlay(true);
    // setup player view
    final nativePlayerView = NativePlayerView();

    //create a widget that can contains player view, then call:
    NativePlayerView(
        onViewCreated: (viewId) async {
            await playerController.setPlayerView(viewId);
        }
    )

Config and play video

Play video source

When authen player and set up player view are all done, prepare a supported video source in String type, then call these command lines to start to play video:

    try{
        playerController.setStartAutoPlay(true);
        await playerController.setSourceVideo(currentSource);
        playerController.build();
    } catch (e, stackTrace) {
        // handle exception
    }

You can use the try/catch to catch exception which cause crashing your app.

Control player

Below is a table of function which can use to control player:

Describe Function Return value
1 pause video playerController.pauseVideo(); void
2 resume video playerController.resumeVideo(); void
3 mute video playerController.muteVideo(); void
4 unmute video playerController.unMuteVideo(); void
5 get duration of video playerController.getVideoDuration(); int
6 check if playing video playerController.isPlaying(); bool
7 get all quality video playerController.getAllQualityVideo(); List<String>
8 apply selected quality playerController.applySelectedQualityVideo(String) void
9 set video volume playerController.setVideoVolume(double audioVol); void
10 seek video playerController.seekTo(int pos); void

Handle event

Player SDK push status and change of player immediately when player created, pause, stop, change config, quality,... So let implements the interface compatible to catch event and handle it.

    @Override
    public void onLogEventListener(String event) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                // handle event
                addLogText("LOG EVENT: : " + event.toString());
            }
        });
    }