我正在尝试使用Brightcove Player播放示例视频。 documentation建议为了实现播放器的基本生命周期回调,应该扩展BrightcovePlayer而不是简单的活动。以下是我如何扩展它:
public class BrightCoveActivity extends BrightcovePlayer {
private static final String BC_TOKEN = "<using a valid token here>";
private String mVideoId;
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_bright_cove);
final BrightcoveVideoView brightcoveVideoView = (BrightcoveVideoView) findViewById(R.id.brightcove_video_view);
super.onCreate(savedInstanceState);
final Catalog catalog = new Catalog(BC_TOKEN);
mVideoId = "<using a valid video ID here";
MediaController controller = new MediaController(this);
brightcoveVideoView.setMediaController(controller);
catalog.findVideoByID(mVideoId, new VideoListener() {
@Override
public void onError(String error) {
throw new RuntimeException(error);
}
@Override
public void onVideo(Video video) {
brightcoveVideoView.add(video);
brightcoveVideoView.start();
}
});
}
}
但是,当我尝试运行应用时,我一直收到IllegalStateException
:
09-09 17:01:51.988: E/AndroidRuntime(21607): Caused by: java.lang.IllegalStateException: brightcoveVideoView needs to be wired up to the layout.
09-09 17:01:51.988: E/AndroidRuntime(21607): at com.brightcove.player.view.BrightcovePlayer.onCreate(BrightcovePlayer.java:180)
此堆栈跟踪最终指向super.OnCreate()
方法。我在“连接”BrightcoveVideoView之前或之后调用超类方法没有区别。
我正在使用:
答案 0 :(得分:1)
您需要在super.onCreate()方法之前设置媒体控制器。
final BrightcoveVideoView brightcoveVideoView = (BrightcoveVideoView)findViewById(R.id.brightcove_video_view);
MediaController controller = new MediaController(this);
brightcoveVideoView.setMediaController(controller);
super.onCreate(savedInstanceState);