android–Exoplayer不循环播放视频

android–Exoplayer不循环播放视频,第1张

概述我在我的Android应用程序中使用Exoplayer来播放视频和音频文件.根据Exoplayerdeveloper’sguide,以循环视频/音频,这是你必须要做的MediaSourcemediaSource=newExtractorMediaSource(videoUri,...);//Loopsthevideoindefinitely.LoopingMediaSourceloopingSource=

我在我的Android应用程序中使用Exoplayer来播放视频和音频文件.根据Exoplayer developer’s guide,以循环视频/音频,这是你必须要做的

MediaSource mediaSource = new ExtractorMediaSource(vIDeoUri, ...);// Loops the vIDeo indefinitely.LooPingMediaSource looPingSource = new LooPingMediaSource(mediaSource);

所以我在Activity的onCreate方法中实现了这个

    BanDWIDthMeter banDWIDthMeter = new DefaultBanDWIDthMeter();    TrackSelection.Factory factory = new AdaptiveTrackSelection.Factory(banDWIDthMeter);    TrackSelector trackSelector = new DefaultTrackSelector(factory);    simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(this,trackSelector);    simpleExoPlayer.setPlayWhenReady(true);    simpleExoPlayerVIEw.setPlayer(simpleExoPlayer);    // Measures banDWIDth during playback. Can be null if not required.    banDWIDthMeter2 = new DefaultBanDWIDthMeter();// Produces DataSource instances through which media data is loaded.    dataSourceFactory = new DefaultDataSourceFactory(this,      Util.getUserAgent(this, applicationname), banDWIDthMeter2);// Produces Extractor instances for parsing the media data.    extractorsFactory = new DefaultExtractorsFactory();    mediaSource = new ExtractorMediaSource(vIDeoUri,dataSourceFactory, extractorsFactory, null, null);    looPingSource = new LooPingMediaSource(mediaSource);    simpleExoPlayer.prepare(mediaSource);

但是我的视频文件的循环没有发生.它只播放一次.

解决方法:

我发现在Exoplayer开发人员指南中遗漏了一些重要信息.创建LooPingMediaSource实例后,不应该调用simpleExoPlayer.prepare(mediaSource);而是调用simpleExoPlayer.prepare(looPingSource);.下面是完整的代码

     BanDWIDthMeter banDWIDthMeter = new DefaultBanDWIDthMeter();    TrackSelection.Factory factory = new AdaptiveTrackSelection.Factory(banDWIDthMeter);    TrackSelector trackSelector = new DefaultTrackSelector(factory);    simpleExoPlayer = ExoPlayerFactory.newSimpleInstance(this,trackSelector);    simpleExoPlayer.setPlayWhenReady(true);    simpleExoPlayerVIEw.setPlayer(simpleExoPlayer);    // Measures banDWIDth during playback. Can be null if not required.    banDWIDthMeter2 = new DefaultBanDWIDthMeter();// Produces DataSource instances through which media data is loaded.    dataSourceFactory = new DefaultDataSourceFactory(this,      Util.getUserAgent(this, applicationname), banDWIDthMeter2);// Produces Extractor instances for parsing the media data.    extractorsFactory = new DefaultExtractorsFactory();        MediaSource mediaSource = new ExtractorMediaSource(vIDeoUri,dataSourceFactory, extractorsFactory, null, null);    // Loops the vIDeo indefinitely.    LooPingMediaSource looPingSource = new LooPingMediaSource(mediaSource);    simpleExoPlayer.prepare(looPingSource);
总结

以上是内存溢出为你收集整理的android – Exoplayer不循环播放视频全部内容,希望文章能够帮你解决android – Exoplayer不循环播放视频所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1108716.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存