在Android中扩展BrightcovePlayer的正确方法是什么? [英] What is the correct way to extend BrightcovePlayer in Android?

查看:121
本文介绍了在Android中扩展BrightcovePlayer的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Brightcove Player播放示例视频。 文档建议为实现播放器的基本生命周期回调,应扩展BrightcovePlayer而不是简单的活动。这是我的扩展方式:

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


}

}

但是,当我尝试运行应用程序时,却不断收到此 IllegalStateException

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)

此堆栈跟踪最终指向 super.OnCreate()方法。在连接 BrightcoveVideoView之前还是之后,调用超类方法都没有关系。

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.

我正在使用:


  1. A 自定义布局此时使用BrightCoveVideoView,除了在相对布局内的videoView之外,没有其他视图。

  2. Eclipse 用于开发(必须这样做,不能使用Android工作室)。我已将旧版.jar文件作为库包含在内(如果我在简单的Activity中而不是BrightcovePlayer活动中执行此项目,则项目运行会很好)。

  3. Brightcove SDK 4.5 (适用于Android)。

  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.


推荐答案

您需要在super.onCreate()方法之前设置媒体控制器。

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

这篇关于在Android中扩展BrightcovePlayer的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆