Quick Advancement of Advanced Player
Play Control Bar
Simple play control bar can see SimpleMediaController class of demo. The class consists of play button and play progress bar. The related interfaces are:
long getDuration()
Get video duration, with the unit of millisecondlong getCurrentPosition
Get the current play position, with the unit of millisecondvoid seekTo(long milliSecond)
Switch to playback somewherestart()
Start playpause()
Pause playOnBufferingUpdateListener
Return the percentage of cached duration to the video playback duration during monitoring and callback, and update the secondary progress bar (cache progress) according to this value.boolean isPlaying()
Whether it is playing
Advanced Setting Interface
BDCloudMediaPlayerProvide multiple advanced setting interfaces:
setBufferSizeInBytes(int size)
The starting play data length during the process of setting buffering; meaning when the [loading] buffering byte number reaches this size, callback BUFFERING_END; the default value is 1*1024*1024 (1M) and the upper limit is 4M;setDecodeMode(int mode)
Set the decoding mode, which can be set as DECODE_AUTO (hardware decoding in priority, and then software decoding) or DECODE_SW (software decoding), with DECODE_AUTO by default;setLogEnabled(boolean enable)
Set to activate the player Logcat output, which is false by default; when releasing the application, the value should be false;setVolume(float leftVolume, float rightVolume)
Set the volume of the left and right sound trackssetInitPlayPosition(long positionInMilliSeconds)
Set the initial playback positionsetLocalCacheEnabled(boolean isEnable, String cachePath)
Whether to enable locally caching while playing; if the cache path is enabled to introduce, it should use the default cache pathsetPcdnEnabled(boolean pcdnEnable, boolean p2pEnable, long networkSoHandle)
Whether Pcdn features and whether to enable P2P; if the Pcdn is enabled, it should be introduced to network library handle, and the current player uses chromium to browse the core network library, which supports quic.muteOrUnmuteAudio(boolean flag)
Whether to play in mute
Video File Prefetch
Advanced player supports video file (except for the clip protocols such as hls and dash) prefetch. Prevention function is provided by BDCloudPlayerManager, and the interfaces involved include:
libsPreLoad(Context context)
Pre-load the playback-related database, if you use the prefetch feature before the player is instantiated, you need to preload the playback databaseprefetch(String url, String ua, String header, int prepareType, int prefetchSize,CyberPlayerManager.HttpDNS httpDns, String businessType)
Video file prefetch. Introduce the headers needed by user agent and request; prepareType is the prefetch type, 0 is prefetch; prefetchSize is the prefetch size, the minimum default value is 30K, the maximum is 600K, dns and businessType scenario information can be empty.stopPrefetch(String url)
Stop prefetching a specified video file. Generally, it is not needed.
Note: If you use the prefetch feature before the player is instantiated, you need to call libsPreLoad (Context context) to preload the playback database. If a player is instantiated, the prefetch interface can be called directly for prefetching.
HLS Video Download
The player supports download and management for M3U8 videos.
Download manager
Download manager is provided as the form of singe instance:
globalVideoDownloadManager = VideoDownloadManager.getInstance(context, userName);
The username is only used for dividing the download records, which is not necessarily the actual username and can be the encryption string or signature string of an actual username.
Download steps
1.Call globalVideoDownloadManager = VideoDownloadManager.getInstance(context, userName)
to get the download management single instance.
2.Call globalVideoDownloadManager.startOrResumeDownloader(url, observer)
to start the download tsk.
Function prototype:
public void startOrResumeDownloader(String url, DownloadObserver observer)
public void startOrResumeDownloaderWithToken(String url, String token, DownloadObserver observer) //Download the encrypted videos
Later, you can also call pause ( `pauseDownloader `), resume ( `startOrResumeDownloader `), delete ( `deleteDownloader `), stop all ( `stopAll `) and other interfaces to manage download tasks.
Among them, while enabling the download, if you want to monitor the download progress and status in real time, you can inherit `DownloadObserver` class and realize `update` methods, and transmit the instances of such class to `startOrResumeDownloader` to realize real-time monitoring. If you don’t want real-time monitoring, make the second parameter of `startOrResumeDownloader` method as null.
public void update(DownloadableVideoItem downloader)
3.Access download task information in real time
During the process of task downloading, call back `update(DownloadableVideoItem downloader)` to get real-time download status.
Downloader object can get the following methods:
Method | Description |
---|---|
getUrl() | Get single download url |
getLocalAbsolutePath() | Get the local absolute path of the downloaded file |
getProgress() | Get download status. |
getStatus() | Get download status(Enumeration type DownloadStatus) |
getErrorCode() | When the download status is Error, get the error code through the interface |
getFailReason() | Get the simple description of download failure or discontinuity |
Note: Error code such as DownloadableVideoItem.ERROR _CODE _INVALID _URL
Whereas, the error code when an error occurs is shown in the table below:
Error code | Description |
---|---|
ERROR_CODE_NO_ERROR | Error free |
ERROR_CODE_INVALID_URL | Address invalid |
ERROR_CODE_NETWORK_FAILED | Network problems |
ERROR_CODE_SDCARD_UNMOUNTED | Local storage problem |
ERROR_CODE_M3U8_\INVALID_FORMAT | m3u8 format problem |
ERROR_CODE_M3U8_SAVE_FAILED | m3u8 storage problem |
ERROR_CODE_M3U8_DRM_INVALID | Invalid key or token related to drm protection |
ERROR_CODE_TS_SAVE_FAILED | Fail to save ts files |
4.Look up the downloading task through url
Get the download task item through `downloadableVideoItem = globalVideoDownloadManager.getDownloadableVideoItemByUrl(url) `, so as to access the information in the item. <br/>
Get all the download units through `globalVideoDownloadManager.getAllDownloadableVideoItems()`, select the unfinished tasks and start resuming download (`startOrResumeDownloader(oneItem.getUrl(), null)`) to realize breakpoint resume.
5.After downloading successfully, DownloadableVideoItem#getLocalAbsolutePath
method gets the local video full path to send to the player for local play.
Caching While Playing
Agent buffer supports HLS and MP4 video cache
Set the video caching while playing steps
mProxyCacheManager = ProxyCacheManager.getInstance()
;Get the cache proxy manager.
String proxyPath = mProxyCacheManager.getProxyUrl(mAppContext, path)
;Get the play agent link.
mProxyCacheManager.setCacheAvailableListener(cacheListener)
;Set the cache progress listener.
setVideoURI(proxyPath)
; Set the agent link to the player
mProxyCacheManager.release()
;Unregister cache monitor to release resource.
For detailed code, please see ‘BDCloudVideoView.java’ in demo.
Record while playing
mRecordController = new RecordController();
Create the record controller.
mRecordController.init(mNewSurfaceTexture,RecordConstants.VIDEO_ENCODE_FRAME_RATE,RecordConstants.DEFAULT_BIT_RATE_GTE_API18);
Initialize the record controller.
mVideoRender.setRenderList(mRecordController.getRenderCallbackList());
Set the render callback.
mRecordController.setRecordSize(mWidth, mHeight);
Set the record size.
mRecordController.startRecord(filePath);
Start recording
mRecordController.setRecordListener(listener);
Set the record listener.
mRecordController.stopRecord();
Stop recording.
For the detailed code, please see BDCloudView.java , TextureRenderView.java
。