What is the correct way to extend BrightcovePlayer in Android?

寵の児 提交于 2019-12-08 06:51:15

问题


I am trying to play a sample video using Brightcove Player. The documentation suggests that to implement basic lifecycle callbacks for the player one should extend BrightcovePlayer instead of a simple activity. Here's how I am extending it:

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();
        }
    });


}

}

However I keep getting this IllegalStateException when I try to run the app:

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)

This stack trace eventually points to the super.OnCreate() method. It does not make a difference whether I call the super-class method before or after I "wire up" the BrightcoveVideoView.

I am using:

  1. A custom layout with BrightCoveVideoView at this point with no other views except the videoView inside a Relative Layout.
  2. Eclipse for development (constrained to do so, can't use Android Studio). I have included the legacy .jar file as a library (the project runs fine if I do this in a simple Activity and not a BrightcovePlayer activity).
  3. Brightcove SDK 4.5 for Android.

回答1:


You need to set the media controller before the super.onCreate() method.

final BrightcoveVideoView brightcoveVideoView = (BrightcoveVideoView)findViewById(R.id.brightcove_video_view);
MediaController controller = new MediaController(this);
brightcoveVideoView.setMediaController(controller);
super.onCreate(savedInstanceState);


来源:https://stackoverflow.com/questions/32478888/what-is-the-correct-way-to-extend-brightcoveplayer-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!