百度智能云

All Product Document

          Multimedia Cloud Processing

          Android Player -2.0- Launching Bulletin

          The interface of Android Player 1.0 is based on BVideoView and 2.0 interface is based on BDCloudMediaPlayer. In order to make the old users successfully migrant and the new users rapidly access, the file has specifically introduced how to migrant the BVideoView of Version 1.0 to BDCloudVideoView of 2.0.

          Migrant to BDCloudVideoView

          Copy BDCloudVideoView code to the project

          The jar package of 2.0 new version player includes only BDCloudMediaPlayer, without View controls; however, Baidu has opened the source of BDCloudVideoView control code, you can get from the root directory or Sample project of the unzip package to copy the code to your project.

          Feature of BDCloudVideoView interface

          BDCloudVideoView interface is closely aligned with the VideoView of the Android system; after replacing BVideoView with BDCloudVideoView, you may find that some interfaces are lost.

          In order to reduce the complexity of BDCloudVideoView external interface, many interfaces at BDCloudMediaPlayer layer are encapsulated in BDCloudVideoView internal methods, you can refer to BDCloudVideoView in the development documentation. Learn how to use BDCloudVideoView.

          Note: Most of the time, please do not modify BDCloudVideoView code to avoid causing trouble for subsequent upgrades.

          Demo reference

          Demo uses BDCloudVideoView to play videos, the following has listed the hierarchical relationship of demo for reference:

          ------------------------------
          Activity and control bar 
          Pack name: com.baidu.cloud.videoplayer.demo 
          Involving: The application interface is shown as AdvancedPlayActivity/SimplePlayActivity, and the control bar is shown as AdvancedMediaController/SimpleMediaController. 
          Action: Create BDCloudVideoView object in Activity, and control the playback in the control bar. 
          --------------↓---------------- 
          BDCloudVideoView 
          Pack name: com.baidu.cloud.videoplayer.widget 
          Involving: BDCloudVideoView control class and the its reliant class The code locates in demo. 
          Action: Encapsulate BDCloudMediaPlayer object, video rendering controls, and have its own status change. 
          --------------↓---------------- 
          BDCloudMediaPlayer 
          Pack name: com.baidu.cloud.media.player 
          Involving: Player and monitor, the code is in bdplayer.jar. 
          Action: Analyze the paly source and fill the rendering target and the actual play control logic. 
          ------------------------------

          Release Interface

          After the new BDCloudVideoView is used, you have to release the player and rendering resources.

          bdCloudVideoView.release(); 

          Note: Please call release interface after disusing BDCloudVideoView instance.

          Change of Time Unit

          Time units concerned in BDCloudVideoView and BDCloudMediaPlayer categories are all millisecond.

          long durationInMilliSeconds = mMediaPlayer.getDuration(); 
          long positionInMilliSeconds = mMediaPlayer.getCurrentPosition(); 
          seekTo(timeInMilliSeconds); 

          Most of the time units in BVideoView of Version 1.0 are second; when setting in the 2.0 new version, the units should multiply by 1,000 based on the original units to transform to be millisecond.

          Monitor the Listener Changes

          Original Listener New listener or alternative method
          BVideoView.OnCompletionListener IMediaPlayer.OnCompletionListener
          BVideoView.OnCompletionWithParamListener None, Completion and Error callbacks should be disposed with separately
          BVideoView.OnErrorListener IMediaPlayer.OnErrorListener
          BVideoView.OnInfoListener IMediaPlayer.OnInfoListener
          BVideoView.OnNetworkSpeedListener None, should call getDownloadSpeed() interface to get download speed rate when enabling the timer by yourself
          BVideoView.OnPlayingBufferCacheListener None, no longer provide [Loading] percentage reminder
          BVideoView.OnPositionUpdateListener None, you need to enable timer to call getCurrentPosition() interface
          BVideoView.OnPreparedListener IMediaPlayer.OnPreparedListener
          BVideoView.OnSeekCompleteListener IMediaPlayer.OnSeekCompleteListener
          BVideoView.OnTotalCacheUpdateListener IMediaPlayer.OnBufferingUpdateListener
          - IMediaPlayer.OnVideoSizeChangedListener
          - BDCloudVideoView.OnPlayerStateListener,Status callback monitoring to conveniently modify the play control bar
          • As for OnPositionUpdateListener, you can refer to startPositionTimer() and stopPositionTimer() relevant functions and the calling logic of the SimpleMediaController class in demo.
          • During the playback of LVB source, according to different playback protocols, it may callback onCompletion or onError when the host push is interrupted. In the program, you are required to check if the VJ host have completed the LVB, if not, the self-write listener will call start() regularly to attempt to continue to pull traffic for playback.

          Interface Change

          The following interfaces may not exist in the 2.0 BDCloudVideoView class, but they can be added in BDCloudVideoView or directly set in the createPlayer() function (recommended) of BDCloudVideoView class if they exist in BDCloudMediaPlayer.

          1.0 Interface 2.0 Interface Description
          BVideoView#getCurrentPlayingUrl() BDCloudVideoView#getCurrentPlayingUrl() -
          BVideoView#selectResolutionType(index) BDCloudVideoView#selectResolutionByIndex(int index)Such method is applicable to the switch of multi-code rate during the playback Switch multi-code. Directly delete the 1.0 interface concerning selectResolutionType(BVideoView.RESOLUTION_TYPE_AUTO); because the actual selection for play is the first Variant, the effect of which is the same even without any setting.
          BVideoView#setCacheBufferSize(long size) BDCloudVideoView#setMaxCacheSizeInBytes(int size) -
          BVideoView#setCacheTime(float timeSec) BDCloudVideoView#setBufferTimeInMs(int milliSec) If the data required for a certain playback duration is buffered, callback the info of Buffering_End.
          BVideoView#setCustomHttpHeader(String header) BDCloudVideoView#setHeaders(Map\<String, String> headers) -
          BVideoView#setDecodeMode(int mode) BDCloudVideoView# setDecodeMode(int mode) 2.0 new version supports AUTO (hardware decoding in priority) and SW, while the old version only supports SW
          BVideoView#setEnableDolby(boolean enableDolby) None -
          BVideoView#setEnableFastStart(boolean isEnable) None, will automatically detect -
          BVideoView#setFirstBufferingTime(float timeSec) BDCloudVideoView#setMaxProbeTime(int maxProbeTime) -
          BVideoView#setLogLevel(int level) BDCloudVideoView#setLogEnabled(boolean enable)
          BVideoView#setUseApmDetect(boolean useApmDetect) BDCloudVideoView#setUseApmDetect(boolean useApmDetect) After it is enabled, you have to embed the APM SDK
          BVideoView#setUserAgent(String strUA) BDCloudVideoView#setHeaders(Map\<String, String> headers) -
          BVideoView#setVideoPath(String path) BDCloudVideoView#setVideoPath(String path) -
          BVideoView#setVideoPath(String path, String withToken) -BDCloudVideoView#setVideoPathWithToken(String path, String token)
          BVideoView#setVideoScalingMode(int mode) BDCloudVideoView#setVideoScalingMode(int mode) The old version supports filling mode and cropping mode; the 2.0 new version adds overspreading mode. -
          BVideoView#setWatermarkText(String text) None, can be realized by adding the floating layer by yourself -
          BVideoView#showCacheInfo(boolean show) BDCloudVideoView#showCacheInfo(boolean show) -
          BVideoView#takeSnapshot() BDCloudVideoView#getBitmap() Support screenshots only when TextureView is displayed.
          - BDCloudVideoView#release() Dispose the playback resources and rendering resources inside BDCloudVideoView

          FAQ About Migration

          Support multiple instances

          • Version 1.0 doesn’t support multi-instance, which should wait for releasing the old BVideoView instance to create a new one;
          • Version 2.0 already supports multi-instance, and there is no influence between different BDCloudVideoViews.

          Better decoding performance

          • Version 1.0 can only use software decoding; version 2.0 supports hardware decoding.
          • The decoding mode of Version 2.0 is default to be AUTO (hardware decoding in priority, and automatically changes to software decoding if the hardware decoder is not found). If you want to use software decoding, you can set through setDecodeMode interface.

          More powerful rendering support

          • The rendering object of the player in Version 1.0 is SurfaceView, which doesn’t support animations such as moving and rotation, and it flashes when rolling in the Views such as Listview
          • The player of Version 2.0 supports TextureView and SurfaceView rendering. The rendering object is TextureView by default, which supports moving and rotating featureal animations and can be normally used in ListView. Differences between SurfaceView and TextureView see BDCloudVideoView in the development document

          If there is any problem during the process of migration, please contact us

          When there is any problem during the process of migration, please submit [Ticket](https://login.bce.baidu.com/? redirect=http://ticket.bce.baidu.com) or [Forum](https://cloud.baidu.com/forum/topic/list? boardId=108), we will contact you as soon as possible.

          The original Baidu AI Cloud Player Android SDK 1.0, please refer to Android SDK 1.0 for the assistant files.

          Previous
          Android-Advanced Player-SDK-Introduction
          Next
          Quick Start