【问题标题】:ExoPlayer did not played mp4 videoExoPlayer 没有播放 mp4 视频
【发布时间】:2020-01-07 08:51:06
【问题描述】:

我坚持在 exoplayer 上播放 mp4 视频,但 exoplayer 只运行 mpd 仅视频请帮助我解决此问题。

当我通过 .mpd 格式的视频播放器将播放流畅,以防 mp4 播放器卡住播放

 lateinit var mDailyWorkOutShowCatResponseList: ArrayList<DailyWorkOutShowCatResponse>
        private lateinit var simpleExoplayer: SimpleExoPlayer
        private var playbackPosition = 0L
        private val dashUrl = "http://rdmedia.bbc.co.uk/dash/ondemand/bbb/2/client_manifest-separate_init.mpd"
        private val bandwidthMeter by lazy {
            DefaultBandwidthMeter()
        }
        private val adaptiveTrackSelectionFactory by lazy {
            AdaptiveTrackSelection.Factory(bandwidthMeter)
        }

        var mUrlStr:String = "http://rdmedia.bbc.co.uk/dash/ondemand/bbb/2/client_manifest-separate_init.mpd"


        fun videoPrepareImplementation(urlStr:String) {


            initializeExoplayer(urlStr)
        }

        override fun getDailyWorkByCategoryOutResponse(dailyWorkOutShowCatResponselist: ArrayList<DailyWorkOutShowCatResponse>) {

            videoPrepareImplementation(mUrlStr)

        }
        override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) {
            if (playbackState == Player.STATE_BUFFERING)
                progressBar.visibility = View.VISIBLE
            else if (playbackState == Player.STATE_READY)
                progressBar.visibility = View.INVISIBLE
        } 
        private fun initializeExoplayer(urlStr: String) {
            simpleExoplayer = ExoPlayerFactory.newSimpleInstance(
                DefaultRenderersFactory(this),
                DefaultTrackSelector(adaptiveTrackSelectionFactory),
                DefaultLoadControl()
            )

            prepareExoplayer(urlStr)
            simpleExoPlayerView.player = simpleExoplayer
            simpleExoplayer.seekTo(playbackPosition)
            simpleExoplayer.playWhenReady = true
            simpleExoplayer.addListener(this)
        }

        private fun releaseExoplayer() {
            playbackPosition = simpleExoplayer.currentPosition
            simpleExoplayer.release()
        }

        private fun buildMediaSource(uri: Uri): MediaSource {
            val dataSourceFactory = DefaultHttpDataSourceFactory("ua", bandwidthMeter)
            val dashChunkSourceFactory = DefaultDashChunkSource.Factory(dataSourceFactory)
            return DashMediaSource(uri, dataSourceFactory, dashChunkSourceFactory, null, null)
        }

        private fun prepareExoplayer(urlStr: String) {
            val uri = Uri.parse(urlStr)
            val mediaSource = buildMediaSource(uri)
            simpleExoplayer.prepare(mediaSource)
        }

kinldy 帮我解决这个问题

【问题讨论】:

    标签: android kotlin exoplayer exoplayer2.x


    【解决方案1】:

    只需使用 ProgressiveMediaSource 和 buildMediaSource 函数就会像

    private fun buildMediaSource(uri: Uri): MediaSource { 
    val dataSourceFactory = DefaultHttpDataSourceFactory("ua", bandwidthMeter) 
    return ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(uri) 
    }
    

    它会播放

    【讨论】:

      【解决方案2】:

      根据代码实验室和我的经验,它应该可以工作。只需检查此代码实验室:- https://codelabs.developers.google.com/codelabs/exoplayer-intro/index.html?index=..%2F..index#0

      在此代码实验室 mp3、mp4 和破折号 URL 工作正常

      【讨论】:

      • exoplayer libaray 的最小 sdk 是 26 我想得到 18 分钟
      • 没有帮助
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-06
      • 2011-05-20
      相关资源
      最近更新 更多