exoplayer2的持续时间是-9223372036854775807,如何解决呢?

时间:2020-05-29 11:48:07

标签: android exoplayer

我录制音频并将其发送到服务器。从服务器获取文件时,我可以听到音频。但是该文件的持续时间为-9223372036854775807。我不明白这很奇怪...简短录制的音频就可以了。但是,当我录制接近1分钟或更长时间的音频时,出现了此问题。当前位置记录良好,但总持续时间记录不正确。该如何解决?

private fun initializePlayer() {
        if (player == null) {
            val trackSelector = DefaultTrackSelector()
            trackSelector.setParameters(
                trackSelector.buildUponParameters().setMaxVideoSizeSd()
            )
            player = ExoPlayerFactory.newSimpleInstance(this,trackSelector)
            binding.musicPlayer.player = player
            binding.musicPlayer.useController=false
            defaultDataSourceFactory = DefaultDataSourceFactory(this, this.getString(R.string.app_name))
            mediaSourceFactory = ProgressiveMediaSource.Factory(defaultDataSourceFactory)
            player!!.playWhenReady = false
            player!!.addListener(object : Player.EventListener {
                override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) {
                    when (playbackState) {
                        Player.STATE_IDLE -> {

                        }
                        Player.STATE_BUFFERING -> {

                        }
                        Player.STATE_READY -> {
                            showLog("totalDuration : "+player!!.duration)
                        }
                        Player.STATE_ENDED -> {
                            player!!.playWhenReady = false
                            activeHolder?.run {
                                binding.progressBar.progress = 0
                                showAudioStartButton(activeHolder!!)
                                activeHolder = null
                            }
                            handlerChangeProgress.removeCallbacks(updateChangeProgressTask)
                            currentAudioPosition = 0
                            maxAudioPosition = 0
                            player!!.seekTo(0)
                        }
                    }
                }
            })
        }
    }



日志

D/TAG: totalDuration : -9223372036854775807

0 个答案:

没有答案