player_sdk 0.0.2 copy "player_sdk: ^0.0.2" to clipboard
player_sdk: ^0.0.2 copied to clipboard

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

MySoha Player SDK #

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

Features #

  • ✅ Secure player
  • ✅ Support FLV, DASH, HLS, MP3, MP4
  • ✅ Support live, VOD
  • ✅ Play, pause, seek, smooth change quality (streaming HLS, DASH)
  • ✅ Mute, unmute, change audio volume
  • ✅ 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());
            }
        });
    }
1
likes
140
points
314
downloads

Publisher

unverified uploader

Weekly Downloads

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

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, logger, plugin_platform_interface

More

Packages that depend on player_sdk