1

我只想在 android.i 中实现 Brightcove 播放器

http://support.brightcove.com/en/docs/accessing-video-content-media-api

http://support.brightcove.com/en/docs/best-practices-android-app-development

从那里,我得到的视频网址为“ http://api.brightcove.com/services/library?command=find_video_by_id&video_id=1520880903001&video_fields=name,length,FLVURL&media_delivery=http&token=jskS1rEtQHy9exQKoc14IcMq8v5x2gCP6yaB7d0hraRtO__.HUux

我在videocloud上获得了特定视频的VideoId,Video_fields。我只想在android本机应用程序的brightcove播放器上使用这些信息播放该视频。

我的代码:

私有静态最终字符串 MyApiToken = "我的令牌"; 私有 ReadAPI mReadAPI = new ReadAPI(MyApiToken); 私人 com.brightcove.mobile.mediaapi.model.Video pVideo;

/** Called when the activity is first created. */
@Override

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main);

    makeAPICall();

}

私人无效 makeAPICall() {

    Log.d("Sample", "Beginning makeAPICall");
    EnumSet<VideoFieldEnum> videoFields = VideoFieldEnum.createEmptyEnumSet(); 
    videoFields.add(VideoFieldEnum.NAME);
    videoFields.add(VideoFieldEnum.LENGTH);
    videoFields.add(VideoFieldEnum.FLVURL);

    try {
        long videoId =My videoId;
        pVideo = mReadAPI.findVideoById(videoId, videoFields, null);
    } catch(Exception e) {
        String msg = e.getMessage();
        Log.e("Sample", msg);
    }

    //Create the player
    BCPlayerView mPlayer;
    mPlayer = (BCPlayerView) findViewById(R.id.player);

    mPlayer.load(pVideo);
    mPlayer.start();
}

}

我还添加了诸如 bc-android-mediapi.jar 和 bc-android-player.jar 之类的库 jar。当我尝试运行时。,我得到了黑屏,视频播放器控制器可见。但是视频没有播放。我需要包括的任何内容更远?

谢谢。

4

1 回答 1

2

我知道这是一篇旧帖子,但我在寻找相同答案时遇到了麻烦。

这是我解决它的方法:

  1. 确保您的应用有权访问互联网

     <uses-permission android:name="android.permission.INTERNET"/>
    
  2. 通过 URL 访问使用读取 API 令牌密钥(如何获取此令牌

  3. 通过强制媒体传输类型为 H264

     theReadAPI.setMediaDeliveryType(MediaDeliveryTypeEnum.HTTP);    
    

希望这可以帮助其他在这个库中遇到问题的人。这是我的完整代码示例:

    Logger mAPILogger = Logger.getLogger("BCAndroidAPILogger");
    ReadAPI theReadAPI = new ReadAPI("read with URL Access token");
    theReadAPI.setMediaDeliveryType(MediaDeliveryTypeEnum.HTTP);
    theReadAPI.setLogger(mAPILogger);

    EnumSet<VideoFieldEnum> videoFields = VideoFieldEnum
            .createEmptyEnumSet();
    videoFields.add(VideoFieldEnum.ID);
    videoFields.add(VideoFieldEnum.NAME);
    videoFields.add(VideoFieldEnum.LENGTH);
    videoFields.add(VideoFieldEnum.RENDITIONS);
    videoFields.add(VideoFieldEnum.FLVURL);
    videoFields.add(VideoFieldEnum.THUMBNAILURL);
    videoFields.add(VideoFieldEnum.VIDEOFULLLENGTH);

    try {
        // Get My Playlist
        Playlist thePlaylist = theReadAPI.findPlaylistById(1234567890123,
                videoFields, null, null);

        BCPlayerView thePlayer = (BCPlayerView) findViewById(R.id.player);
        thePlayer.logEnabled(true);
        thePlayer.load(thePlaylist.getVideos().get(0));
        thePlayer.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
于 2012-11-12T20:39:26.923 回答