音频播放器的开发。如何在用户操作时停止更新搜索栏通知(Mediastyle)

问题描述 投票:0回答:1

我正在开发一个音频播放器,以 Mediastyle 风格创建一个通知,带有播放、暂停和搜索栏按钮。搜索栏每半秒更新一次,从媒体播放器的当前位置获取值。一切正常,直到用户独立开始倒带搜索栏。

当用户移动滑块时,触发回调:

MediaSession.setCallback(new MediaSessionCompat.Callback() {
        @Override
        public void onSeekTo(long pos) {
            mediaPlayer.seekTo((int)position);
        }

但是由于 seekbar 每半秒更新一次,用户不能无限移动 seekbar 滑块。 问题:如何在用户操作时停止更新搜索栏读数。我知道seekbar有回调:

private boolean isTouch;
public void setSeekbar(SeekBar seekBarPlayer) {
    seekBarPlayer.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            isTouch = true;
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            isTouch = false;
        }
    });
}

但是我无法拦截它们,因为我没有对当前搜索栏的引用来覆盖回调。

android notifications seekbar
1个回答
0
投票

尝试使用它

mediaSession.setPlaybackState(
    PlaybackStateCompat.Builder()
        .setState(
            PlaybackStateCompat.STATE_PLAYING,
                        
            // Playback position.
            // Used to update the elapsed time and the progress bar. 
            mediaPlayer.currentPosition.toLong(), 
                        
            // Playback speed. 
            // Determines the rate at which the elapsed time changes. 
            playbackSpeed
        )

        // isSeekable. 
        // Adding the SEEK_TO action indicates that seeking is supported 
        // and makes the seekbar position marker draggable. If this is not 
        // supplied seek will be disabled but progress will still be shown.
        .setActions(PlaybackStateCompat.ACTION_SEEK_TO)
        .build()
)
© www.soinside.com 2019 - 2024. All rights reserved.