선택 사항: 재정의하면BrightcoveExoPlayerVideoView클래스 또는 Brightcove 플레이어 및 카탈로그를 사용하지 않는 경우 Video Cloud 게시자 ID를 Video Cloud Analytics로 보내야합니다. 분석을 사용하여이를 수행 할 수 있습니다. setAccount()방법. 이를 통해 비디오 클라우드 분석에서 이 앱에 대한 데이터를 볼 수 있습니다.
package com.brightcove.playvideos;
import android.os.Bundle;
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 java.net.URISyntaxException;
public class MainActivity extends BrightcovePlayer {
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
// Create the video view
brightcoveVideoView = (BrightcoveExoPlayerVideoView) findViewById(R.id.brightcove_video_view);
super.onCreate(savedInstanceState);
// Optional: For Brightcove Player customers to register their apps
Analytics analytics = brightcoveVideoView.getAnalytics();
analytics.setAccount("your account Id");
// Define a video from a remote server
Video video = Video.createVideo("https://sdks.support.brightcove.com/assets/videos/hls/greatblueheron/greatblueheron.m3u8",
DeliveryType.HLS);
// Load a remote poster image
try {
java.net.URI myposterImage = new java.net.URI("https://sdks.support.brightcove.com/assets/images/general/Great-Blue-Heron.png");
video.getProperties().put(Video.Fields.STILL_IMAGE_URI, myposterImage);
} catch (URISyntaxException e) {
e.printStackTrace();
}
// Add video to the view
brightcoveVideoView.add(video);
// Start video playback
brightcoveVideoView.start();
}
}
애플리케이션을 실행하거나 디버그하여 비디오 재생을 확인하십시오.
비디오 가져 오기 및 재생
이 섹션에서는Catalog클래스를 사용하여 Video Cloud 서버에서 단일 비디오를 검색 한 다음 재생합니다.
이com.brightcove.player.edge.Catalog클래스는브라이트코브 재생 API에서 비디오 및 재생목록을 검색하기 위한 비동기 메서드를 제공합니다. 이 API는 Video Cloud 라이브러리에서 콘텐츠를 검색하는 데 권장되는 최신 API입니다.
불필요한 코드 제거
이전 앱의 일부 코드는 더 이상 필요하지 않습니다. onCreate()메서드에서 슈퍼클래스를 입력한 후 모든 코드를 제거합니다.
확인onCreate()방법은 다음과 같이 나타납니다.
public class MainActivity extends BrightcovePlayer {
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
// Create the video view
brightcoveVideoView = (BrightcoveExoPlayerVideoView) findViewById(R.id.brightcove_video_view);
super.onCreate(savedInstanceState);
}
}
카탈로그에서 비디오 검색
Video Cloud Studio 계정에서 다음 정보를 수집합니다.
계정 ID
비디오 ID
정책 키
프로젝트에서 사용자 정의 값을 정의하십시오. res/values/strings.xml파일을 열고 값을 업데이트합니다.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Application name -->
<string name="app_name">PlayVideos</string>
<!-- A sample Brightcove Edge Account ID -->
<string name="account">your account id</string>
<!-- A sample Brightcove Edge Policy Key -->
<string name="policy">your policy key</string>
<!-- A sample Brightcove Video ID -->
<string name="videoId">your video id</string>
</resources>
MainActivity.java파일로 돌아가서 SDK에서 이벤트 이미터를 가져옵니다.
// Get the event emitter from the SDK
EventEmitter eventEmitter = brightcoveVideoView.getEventEmitter();
이전 단계에서 정의한 계정 ID 및 정책 키 값을 사용하여 Brightcove Edge 서비스에서 비디오를 가져오는 카탈로그 요청을 생성합니다.
// Create a catalog request to fetch a video
String account = getString(R.string.account);
Catalog catalog = new Catalog.Builder(eventEmitter, account)
.setBaseURL(Catalog.DEFAULT_EDGE_BASE_URL)
.setPolicy(getString(R.string.policy))
.build();
카탈로그 사용findVideoByID()비디오 ID와VideoListener콜백.
에서onVideo()방법, 비디오를 추가brightcoveVideoView을 클릭 한 다음 비디오를 시작하십시오.
// Get the video by ID
catalog.findVideoByID(getString(R.string.videoId), new VideoListener() {
@Override
public void onVideo(Video video) {
// Add video to the view
brightcoveVideoView.add(video);
// Start video playback
brightcoveVideoView.start();
}
});
MainActivity클래스의 전체 코드는 다음과 유사해야합니다.
public class MainActivity extends BrightcovePlayer {
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
// Create the video view
brightcoveVideoView = (BrightcoveExoPlayerVideoView) findViewById(R.id.brightcove_video_view);
super.onCreate(savedInstanceState);
// Get the event emitter from the SDK
EventEmitter eventEmitter = brightcoveVideoView.getEventEmitter();
// Create a catalog request to fetch a video
String account = getString(R.string.account);
Catalog catalog = new Catalog.Builder(eventEmitter, account)
.setBaseURL(Catalog.DEFAULT_EDGE_BASE_URL)
.setPolicy(getString(R.string.policy))
.build();
// Get the video by ID
catalog.findVideoByID(getString(R.string.videoId), new VideoListener() {
@Override
public void onVideo(Video video) {
// Add video to the view
brightcoveVideoView.add(video);
// Start video playback
brightcoveVideoView.start();
}
});
}
}
앱을 실행하여 비디오 재생을 확인하십시오.
재생 목록 가져 오기 및 재생
이 섹션에서는Catalog클래스를 사용하여 Video Cloud 서버에서 재생 목록을 검색 한 다음 재생 목록의 비디오를 재생합니다.
이com.brightcove.player.edge.Catalog클래스는브라이트코브 재생 API에서 비디오 및 재생목록을 검색하기 위한 비동기 메서드를 제공합니다. 이 API는 Video Cloud 라이브러리에서 콘텐츠를 검색하는 데 권장되는 최신 API입니다.
불필요한 코드 제거
이전 앱의 일부 코드는 더 이상 필요하지 않습니다. 카탈로그의 호출을 제거하십시오. findVideoByID()방법 및 관련VideoListener익명 콜백 기능.
// Get the video by ID
catalog.findVideoByID(getString(R.string.videoId), new VideoListener() {
@Override
public void onVideo(Video video) {
// Add video to the view
brightcoveVideoView.add(video);
// Start video playback
brightcoveVideoView.start();
}
});
카탈로그에서 재생 목록 검색
기존 카탈로그 인스턴스는 재생 목록을 검색하는 데 작동하므로변경할 필요가 없습니다다음 코드 줄에 :
// Get the event emitter from the SDK
EventEmitter eventEmitter = brightcoveVideoView.getEventEmitter();
// Create a catalog request to fetch a video
String account = getString(R.string.account);
Catalog catalog = new Catalog.Builder(eventEmitter, account)
.setBaseURL(Catalog.DEFAULT_EDGE_BASE_URL)
.setPolicy(getString(R.string.policy))
.build();
Video Cloud Studio에서미디어모듈에서 재생 목록을 선택하고재생 목록 ID .
res/values/strings.xml파일을 열고 플레이리스트 ID에 대한 항목을 추가합니다.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Application name -->
<string name="app_name">PlayVideos</string>
<!-- A sample Brightcove Edge Account ID -->
<string name="account">your account id</string>
<!-- A sample Brightcove Edge Policy Key -->
<string name="policy">your policy key</string>
<!-- A sample Brightcove Playlist ID -->
<string name="playlistId">your playlist id</string>
</resources>
카탈로그 사용findPlaylistByID()재생 목록 ID와PlaylistListener콜백.
에서onPlaylist()메서드, 재생 목록에서 비디오를 검색하고 모든 비디오를brightcoveVideoView을 클릭 한 다음 첫 번째 비디오를 시작하십시오.
// Get the playlist by ID
String playlist = getString(R.string.playlistId);
catalog.findPlaylistByID(playlist, new PlaylistListener() {
@Override
public void onPlaylist(Playlist playlist) {
// Add playlist to the view
brightcoveVideoView.addAll(playlist.getVideos());
// Start playback
brightcoveVideoView.start();
}
});
MainActivity클래스의 전체 코드는 다음과 유사해야합니다.
public class MainActivity extends BrightcovePlayer {
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
// Create the video view
brightcoveVideoView = (BrightcoveExoPlayerVideoView) findViewById(R.id.brightcove_video_view);
super.onCreate(savedInstanceState);
// Get the event emitter from the SDK
EventEmitter eventEmitter = brightcoveVideoView.getEventEmitter();
// Create a catalog request to fetch a video
String account = getString(R.string.account);
Catalog catalog = new Catalog.Builder(eventEmitter, account)
.setBaseURL(Catalog.DEFAULT_EDGE_BASE_URL)
.setPolicy(getString(R.string.policy))
.build();
// Get the playlist by ID
String playlist = getString(R.string.playlistId);
catalog.findPlaylistByID(playlist, new PlaylistListener() {
@Override
public void onPlaylist(Playlist playlist) {
// Add playlist to the view
brightcoveVideoView.addAll(playlist.getVideos());
// Start playback
brightcoveVideoView.start();
}
});
}
}