概覽
視訊雲端客戶可以從視訊雲端工作室存取其媒體資料和中繼資料。布萊特灣玩家的客戶將提供其媒體內容的 URL。
視訊雲端客戶
身為視訊雲端客戶,您可以存取儲存在視訊雲端工作室中的媒體資料。有關更多信息,請參見適用於Android代碼示例的Player SDK。
擷取媒體資料
您可以使用播放 API,從視訊雲端媒體櫃擷取您的視訊和播放清單資料。如需有關 API 的詳細資訊,請參閱播放 API 概觀文件。
-
使用com.brightcove.player.edge.Catalog類方法從Brightcove的Playback API中檢索您的視頻和播放列表。您的請求可以提供視頻/播放清單
ID
或ReferenceID
.此服務將發出 URL 請求並解析返回的數據。 -
對於此要求,您將需要一個原則金鑰。如果您不熟悉原則金鑰,請參閱原則 API 概觀文件。
這是有關如何使用
com.brightcove.player.edge.Catalog
類:package com.brightcove.player.samples.exoplayer.basic; import android.os.Bundle; import android.util.Log; import com.brightcove.player.edge.Catalog; import com.brightcove.player.edge.VideoListener; import com.brightcove.player.event.EventEmitter; import com.brightcove.player.model.Video; import com.brightcove.player.view.BrightcoveExoPlayerVideoView; import com.brightcove.player.view.BrightcovePlayer; /** * This app illustrates how to use the ExoPlayer with the Brightcove * Native Player SDK for Android. */ public class MainActivity extends BrightcovePlayer { private final String TAG = this.getClass().getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_main); brightcoveVideoView = (BrightcoveExoPlayerVideoView) findViewById(R.id.brightcove_video_view); super.onCreate(savedInstanceState); // Get the event emitter from the SDK and create a catalog request to fetch a video from the // Brightcove Edge service, given a video id, an account id and a policy key. EventEmitter eventEmitter = brightcoveVideoView.getEventEmitter(); Catalog catalog = new Catalog(eventEmitter, getString(R.string.account), getString(R.string.policy)); catalog.findVideoByID(getString(R.string.videoId), new VideoListener() { // Add the video found to the queue with add(). // Start playback of the video with start(). @Override public void onVideo(Video video) { Log.v(TAG, "onVideo: video = " + video); brightcoveVideoView.add(video); brightcoveVideoView.start(); } }); } }
- 的視頻對象提供檢索媒體信息的方法,如下所示:
catalog.findVideoByID(getString(R.string.videoId), new VideoListener() { // Add the video found to the queue with add(). // Start playback of the video with start(). @ Override public void onVideo(Video video) { Log.v(TAG, "onVideo: video = " + video); Log.v(TAG, "onVideo: videoID = " + video.getId()); Log.v(TAG, "onVideo: videoName = " + video.getName()); Log.v(TAG, "onVideo: videoDescription = " + video.getDescription()); Log.v(TAG, "onVideo: videoImage = " + video.getStillImageUri()); Log.v(TAG, "onVideo: sourceCollections = " + video.getSourceCollections()); SourceCollection dashCollection = video.getSourceCollections().get(DeliveryType.DASH); if (dashCollection != null) { Set < Source > sources = dashCollection.getSources(); for (Source source: sources) { if (!TextUtils.isEmpty(source.getUrl())) { Log.v(TAG, "onVideo: DASH source = " + source.getUrl()); } } } brightcoveVideoView.add(video); brightcoveVideoView.start(); } });
以上
Log()
方法返回以下媒體信息: -
您可能需要查看自定義字段(如果有)是否存在
Video
目的。將以下代碼添加到onVideo
回調方法循環customField
地圖。catalog.findVideoByID(getString(R.string.videoId), new VideoListener() { @ Override public void onVideo(Video video) { Map<String, String> customFieldMap = (HashMap<String, String>) video.getProperties().get(Video.Fields.CUSTOM_FIELDS); if (customFieldMap != null && customFieldMap.size() > 0) { for (Map.Entry<String, String> entry : customFieldMap.entrySet()) { Log.v(TAG, "onVideo: Custom fields: Key: " + entry.getKey() + " Value: " + entry.getValue()); } } brightcoveVideoView.add(video); brightcoveVideoView.start(); } });
這是您可以從上面的代碼中看到的日誌輸出示例:
MainActivity: onVideo: Custom fields: Key: genre Value: Action MainActivity: onVideo: Custom fields: Key: customlist Value: customListValue1
請注意,自定義字段可以表示為
Strings
要么Lists
。即使自定義字段可以是List
類型,它是一個列表String
值,從中選擇一個值來設置字段的值。
經過地理過濾的視頻
適用於Android的Brightcove Player SDK支持經過地理過濾的視頻。
您可以通過兩種方法向視頻添加地理過濾,以控制可以(或不能)在哪些國家/地區觀看視頻:
在您的Android應用中,當您使用Brightcove的邊緣檢索視頻時目錄針對該視頻進行地理過濾的國家/地區的對象(播放API),您應該會看到以下消息:
error { message: Access to this resource is forbidden by access policy.
client_geo: us
error_subcode: CLIENT_GEO
error_code: ACCESS_DENIED }
布萊特灣玩家顧客
身為布萊特灣播放器客戶,您將提供視訊資產的網址。
這是將視頻添加到視頻視圖並開始播放的示例:
import com.brightcove.player.model.DeliveryType;
import com.brightcove.player.model.Video;
import com.brightcove.player.view.BrightcoveExoPlayerVideoView;
import com.brightcove.player.view.BrightcovePlayer;
import com.brightcove.player.analytics.Analytics;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BrightcoveVideoView brightcoveVideoView = (BrightcoveVideoView) findViewById(R.id.brightcove_video_view);
Analytics analytics = brightcoveVideoView.getAnalytics();
analytics.setAccount("123456789");
MediaController controller = new MediaController(this);
brightcoveVideoView.setMediaController(controller);
brightcoveVideoView.add(Video.createVideo("http://solutions.brightcove.com/bcls/assets/videos/Bird_Titmouse.mp4", DeliveryType.MP4));
brightcoveVideoView.start();
}
接下來,讓我們看一下事件如何在SDK架構內工作。