我在使用ExoPlayer时遇到了麻烦.我用一个来流式传输广播电台



当流式传输广播电台时,流在一段时间延迟后停止并再次播放。并且此问题在蓝牙耳机中重现。

2020-06-29 12:59:02.577 6159-6645/com.example.player E/AudioTrack: start(): 0x931f7000, mState = 1
2020-06-29 12:59:02.584 6159-6159/com.example.player D/MediaService: onPlayerStateChanged: playWhenReady - true; playbackState - 3
2020-06-29 12:59:02.625 6159-6645/com.example.player D/AudioTrack: correcting timestamp time for pause, currentTimeNanos: 177361604116546 < limitNs: 177364334867316 < mStartNs: 177364574867316
2020-06-29 12:59:02.625 6159-6645/com.example.player W/AudioTrack: retrograde timestamp time corrected, 177364334867316 < 177364578496700
2020-06-29 12:59:02.635 6159-6645/com.example.player D/AudioTrack: correcting timestamp time for pause, currentTimeNanos: 177361604116546 < limitNs: 177364334867316 < mStartNs: 177364574867316
2020-06-29 12:59:02.635 6159-6645/com.example.player W/AudioTrack: retrograde timestamp time corrected, 177364334867316 < 177364578496700
2020-06-29 13:01:58.234 6159-6645/com.example.player D/AudioTrack: pause(): 0x931f7000, mState = 0
2020-06-29 13:01:58.239 6159-6159/com.example.player D/MediaService: onPlayerStateChanged: playWhenReady - true; playbackState - 2
2020-06-29 13:02:05.073 6159-6645/com.example.player E/AudioTrack: start(): 0x931f7000, mState = 2
2020-06-29 13:02:05.079 6159-6159/com.example.player D/MediaService: onPlayerStateChanged: playWhenReady - true; playbackState - 3
2020-06-29 13:02:05.122 6159-6645/com.example.player D/AudioTrack: correcting timestamp time for pause, currentTimeNanos: 177540976640019 < limitNs: 177546830466942 < mStartNs: 177547070466942
2020-06-29 13:02:05.122 6159-6645/com.example.player W/AudioTrack: retrograde timestamp time corrected, 177546830466942 < 177547073697634
2020-06-29 13:02:14.816 6159-6645/com.example.player D/AudioTrack: pause(): 0x931f7000, mState = 0

我像这样创造外线玩家

exoPlayer = SimpleExoPlayer.Builder(
this,
DefaultRenderersFactory(this),
DefaultTrackSelector(this),
DefaultLoadControl(),
bandwidthMeter,
Looper.getMainLooper(),
AnalyticsCollector(Clock.DEFAULT),
true,
Clock.DEFAULT
).build()

然后

exoPlayer.playWhenReady = true
prepareExoPlayer()
setSessionState(PlaybackStateCompat.STATE_PLAYING)
...
private fun prepareExoPlayer() {
val mediaSource = buildMediaSource()
exoPlayer.prepare(mediaSource)
}
private fun buildMediaSource(): MediaSource {
val dataSourceFactory = DefaultDataSourceFactory(
this,
Util.getUserAgent(baseContext, getString(R.string.app_name)),
bandwidthMeter
)
var url = currentStation.middleStream
return ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(url))
}

如果您使用ExoPlayer播放通过HTTP提供的音频,请尝试创建特定版本的工厂,例如:

val dataSourceFactory = DefaultHttpDataSourceFactory(
Util.getUserAgent(baseContext, getString(R.string.app_name))
)

相关内容

  • 没有找到相关文章

最新更新