ExoPlayer没有播放mp4视频

时间:2020-01-07 08:51:06

标签: android kotlin exoplayer exoplayer2.x

我被困在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)
        }

请帮我解决这个问题

1 个答案:

答案 0 :(得分:1)

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

awk '!a[$0]++'

它将播放

相关问题