在Android中扩展BrightcovePlayer的正确方法是什么?

时间:2015-09-09 11:54:05

标签: android eclipse brightcove

我正在尝试使用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之前或之后调用超类方法没有区别。

我正在使用:

  1. 此时使用BrightCoveVideoView的自定义布局,除了相对布局中的videoView之外没有其他视图。
  2. Eclipse 进行开发(限制这样做,不能使用Android Studio)。我已将遗留的.jar文件作为库包含在内(如果我在一个简单的Activity而不是BrightcovePlayer活动中执行此项目,该项目运行正常)。
  3. 适用于Android的Brightcove SDK 4.5

1 个答案:

答案 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);