GitHub address: wlplayer



Wlplayer v1.0

Android based on: FFmpeg+OpenSL+OpenGL+Mediacodec video playback SDK, can play network, local and broadcast streaming media. Support the current playing page to directly switch the playing source; Support real-time video screenshots; GPU decoding is preferred for faster decoding speed. It can play in the case of 1080P, 2K, 4K, etc.; Encapsulate common playback state callback, easy access.

APP Demo (Note: Video data is from Panda TV, broadcast data is from China Broadcasting Network)

App Demo download address

 

 







A, API v1.0

1. Callback interface

WlOnPreparedListener // Video loading callback WlOnLoadListener // Video duration and current playback duration callback this interface WlOnInfoListener // Video error callback this interface WlOnErrorListener // Callback to this interface when a video is played. WlOnCompleteListener // Callback to this interface when a video screenshot is played. WlOnCutVideoImgListener // Callback to this interface when the playing page is switched to the playing source (stop(false)), On this interface, you can reset the new playback source WlOnStopListenerCopy the code

2, methods,

Void setDataSource(String dataSource); Void setOnlyMusic(Boolean onlyMusic) // Set video render glsurfaceView void setWlGlSurfaceView(WlGlSurfaceView WlGlSurfaceView) // Ready to play (corresponding callback interface) void prepared() // When ready, Void start() // Pause void Pause () // Play (relative to pause) void Resume () // Stop true: Void stop(final Boolean exit) //seek to any time (not key frame, Void seek(final int secds) // get total playback duration int getDuration() // getVideoWidth int getVideoWidth() // get video height int Int getAudioChannels() void setAudioChannels(int index)Copy the code

Ii. Access process

1. Add a layout

<com.ywl5320.opengles.WlGlSurfaceView
    android:id="@+id/surfaceview"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
Copy the code

2. Create a player object

private WlGlSurfaceView surfaceview; private WlPlayer wlPlayer; @Override public void onCreate(Bundle savedInstanceState) { wlPlayer = new WlPlayer(); wlPlayer.setOnlyMusic(false); // true: broadcast; false: video wlplayer. setDataSource(pathurl); / / set playback source wlPlayer. SetWlGlSurfaceView (surfaceview); // Play radio without video render layout}Copy the code

3. Get ready to play

wlPlayer.prepared();
Copy the code

4. Add callback (note: all in child thread)

/ / video ready to play when the callback wlPlayer setWlOnPreparedListener (new WlOnPreparedListener () {@ Override public void onPrepared () { wlPlayer.start(); // Start playing}}); / / load callback wlPlayer. SetWlOnLoadListener (new WlOnLoadListener () {@ Override public void onLoad (Boolean load) {/ / true: load False: load complete Message Message = message.obtain (); message.what = 1; message.obj = load; handler.sendMessage(message); }}); / / play time information callback wlPlayer setWlOnInfoListener (new WlOnInfoListener () {@ Override public void onInfo (WlTimeBean WlTimeBean) {// Current playing time and total time Message Message = message.obtain (); message.what = 2; message.obj = wlTimeBean; MyLog.d("nowTime is " +wlTimeBean.getCurrt_secds()); handler.sendMessage(message); }}); / / error callback wlPlayer. SetWlOnErrorListener (new WlOnErrorListener () {@ Override public void onError (int code, String msg) { MyLog.d("code:" + code + ",msg:" + msg); Message message = Message.obtain(); message.obj = msg; message.what = 3; handler.sendMessage(message); }}); / / play complete callback wlPlayer. SetWlOnCompleteListener (new WlOnCompleteListener () {@ Override public void the onComplete () { MyLog.d("complete ....................." ); wlPlayer.stop(true); }}); . / / video screenshots callback wlPlayer setWlOnCutVideoImgListener (new WlOnCutVideoImgListener () {@ Override public void onCutVideoImg (Bitmap bitmap) { Message message = Message.obtain(); message.what = 4; message.obj = bitmap; handler.sendMessage(message); }}); // Stop the playback callback (this method is only called if wlplayer.stop (false), etc., Can handle switch inside sources operating) wlPlayer. SetWlOnStopListener (new WlOnStopListener () {@ Override public void onStop () {Message Message = Message.obtain(); message.what = 3; handler.sendMessage(message); }});Copy the code

If it helps you, you can choose to reward oh ~

TODO

Compatibility and performance optimization


note

Current environment: FFMPEG-3.4, AS-3.0, NK-14B, Miui mobile 2A

CPU: arm (only)

2018-01-01 Happy New Year!


Create by:ywl5320