[Huawei Developers] XDARoni:
Playback Process

1. Create a WisePlayer instance.

A WisePlayerFactory instance is returned when the WisePlayer initialization is successful. Your app will use this instance to call createWisePlayer() to create WisePlayer.

WisePlayer player = factory.createWisePlayer();

2. Set parameters such as the video URL.

a. Set listeners. Your app will react based on listener callbacks. For more information about the listeners, please refer to Interface Summary.

player.setErrorListener(errorListener);
player.setEventListener(eventListener);
player.setResolutionUpdatedListener(resolutionUpdatedListener);
player.setReadyListener(readyListener);
player.setLoadingListener(loadingListener);
player.setPlayEndListener(playEndListener);
player.setSeekEndListener(seekEndListener);

b. Set required parameters, such as playback type, bookmark, and repeat mode.

player.setVideoType(0);
player.setBookmark(10000);
player.setCycleMode(1);

c. Specify the address from which WisePlayer retrieves video content to play.

WisePlayer provides multiple APIs for setting the video URL, which your app can call as needed.

// Method 1: Set a single URL for a video.
player.setPlayUrl("http://192.168.0.100:8080/a.mp4");

// Method 2: Set multiple URLs (one primary, the other standby) for a video.
// player.setPlayUrl(new String[] {"http://192.168.1.100:8080/b.mp4", "http://192.168.1.101:8080/b.mp4"});

d. Set a view to display the video.

Currently, WisePlayer supports SurfaceView and TextureView. Make sure that a valid view is available; otherwise, the playback will fail.

player.setView(surfaceView);

3. Call ready to start loading data.

player.ready();

4. Call start in the onReady event notification to start playback.

After receiving the onReady event notification, your app calls the start method of WisePlayer to start playback. Then your app can use the getDuration() and getCurrentTime() APIs to obtain the video duration and playback progress for displaying the progress bar. WisePlayer parameters can be obtained only after the onReady event notification is received.

player.start();

a. Register ResolutionUpdatedListener, using which WisePlayer detects video resolution changes.

public void onResolutionUpdated(WisePlayer wp, int width, int height) {
// Your app can adjust the view size based on the width and height of the new resolution.
}

b. Drag the slider on the progress bar.

// Drag the slider to the "3600000 milliseconds" position.
player.seek(3600000);

c. Pause the playback and resume it.

To resume the playback, call the start method.

player.pause();
player.start();

d. Suspend WisePlayer.

If your app uses SurfaceView to display the video, it will suspend WisePlayer upon receiving a surfaceDestroyed event. If your app uses TextureView to display the video, it will suspend WisePlayer upon receiving an onSurfaceTextureDestroyed event.

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
if (player != null) {
player.suspend();
}
}

e. Resume WisePlayer.

If your app uses SurfaceView to display the video, it will call the view set beforehand and resume WisePlayer upon receiving a surfaceCreated event. If your app uses TextureView to display the video, it will call the view set beforehand and resume WisePlayer upon receiving an onSurfaceTextureAvailable event.

@Override
public void surfaceCreated(SurfaceHolder holder) {
if (player != null) {
player.setView(surfaceView);
// To resume WisePlayer when you bring your app to the foreground, call the resume API. You can determine whether the playback automatically starts after your app is brought to the foreground by passing a parameter.
player.resume(-1);
}
}

f. Change the view size.

Your app must notify WisePlayer of the view size change. Otherwise, the playback is affected. If your app uses SurfaceView to display the video, the setSurfaceChange API will be called when a surfaceChanged event is received. If your app uses TextureView to display the video, the setSurfaceChange API will be called when an onSurfaceTextureSizeChanged event is received.

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
if (player != null) {
player.setSurfaceChange();
}
}

5. Call release to stop playback and release the WisePlayer instance.

a. Stop the playback.

player.stop();

b.Release WisePlayer.

To stop playing, your app must call the following APIs:

// Set the WisePlayer listener to null.
player.setErrorListener(null);
player.setEventListener(null);
player.setResolutionUpdatedListener(null);
player.setReadyListener(null);
player.setLoadingListener(null);
player.setPlayEndListener(null);
player.setSeekEndListener(null);

// Release WisePlayer and set the WisePlayer object to null.
player.release();
player = null;