3

I'm trying to make a seekbar which shows playback position And I found something weird. The value of current position it not inscreasing. It should be increased by asc.

Log

D/RecordingFragment: #@ current_position: 0
D/RecordingFragment: #@ current_position: 0
D/RecordingFragment: #@ current_position: 0
D/RecordingFragment: #@ current_position: 5
D/RecordingFragment: #@ current_position: 15
D/RecordingFragment: #@ current_position: 27
D/RecordingFragment: #@ current_position: 37
D/RecordingFragment: #@ current_position: 49
D/RecordingFragment: #@ current_position: 61
D/RecordingFragment: #@ current_position: 73
D/RecordingFragment: #@ current_position: 84
D/RecordingFragment: #@ current_position: 96
D/RecordingFragment: #@ current_position: 108
D/RecordingFragment: #@ current_position: 118
D/RecordingFragment: #@ current_position: 129
D/RecordingFragment: #@ current_position: 141
D/RecordingFragment: #@ current_position: 153
D/RecordingFragment: #@ current_position: 165
D/RecordingFragment: #@ current_position: 177
D/RecordingFragment: #@ current_position: 188
D/RecordingFragment: #@ current_position: 199
D/RecordingFragment: #@ current_position: 210
D/RecordingFragment: #@ current_position: 221
D/RecordingFragment: #@ current_position: 232
D/RecordingFragment: #@ current_position: 243
D/RecordingFragment: #@ current_position: 254
D/RecordingFragment: #@ current_position: 145 <- why?
D/RecordingFragment: #@ current_position: 156
D/RecordingFragment: #@ current_position: 168
D/RecordingFragment: #@ current_position: 180
D/RecordingFragment: #@ current_position: 191
D/RecordingFragment: #@ current_position: 203
D/RecordingFragment: #@ current_position: 217
D/RecordingFragment: #@ current_position: 228
D/RecordingFragment: #@ current_position: 239
D/RecordingFragment: #@ current_position: 250
D/RecordingFragment: #@ current_position: 262
D/RecordingFragment: #@ current_position: 274
D/RecordingFragment: #@ current_position: 285
D/RecordingFragment: #@ current_position: 296
D/RecordingFragment: #@ current_position: 308
D/RecordingFragment: #@ current_position: 320
D/RecordingFragment: #@ current_position: 332
D/RecordingFragment: #@ current_position: 343
D/RecordingFragment: #@ current_position: 354
D/RecordingFragment: #@ current_position: 365

Here is Fragment code

    // update position in every 10ms
    private fun updateCurrentPosition() {
        timer = Timer("current_position", false).schedule(0, 10) {
            Log.d(LOG_TAG, "#@ current_position 타이머: ${player.currentPosition}")
            recordingViewModel.currentPosition.postValue(player.currentPosition)
        }
    }

Observing code

recordingViewModel.currentPosition.observe(this, Observer { position ->
            if(position != null) {
                sbPlayingControll.progress = position
            }
        })

Audio file format (it's recorded audio file from MediaRecorder

            setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP)
            setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB)
            setAudioSamplingRate(1000 * 16)
            setAudioEncodingBitRate(1000 * 128)
the1900
  • 495
  • 1
  • 5
  • 16
  • any luck with that, have you figured it out? – snachmsm May 20 '20 at 13:00
  • @snachmsm No but I concluded that is because of android emulator. It's not happen when run on real device! – the1900 May 29 '20 at 06:07
  • I'm running on real devices, it was reproducable... "was" because I ended up with ExoPlayer – snachmsm May 29 '20 at 11:33
  • @snachmsm Oh really? so you are saying getCurrentPosition method of ExoPlayer does work well right? I didn't know the method implementing is different beteween ExoPlayer and MediaPlayer. – the1900 Jun 03 '20 at 00:44
  • `ExoPlayer` is way more reliable, especially across different versions of Android, which we must support. In my case `getCurrentPosition` of `ExoPlayer` is returning negative value when it just warmed up and start play first audio file - I'm using `Math.max(0, exPl.getCurrentPosition())` then. Besides that this lib is awesome – snachmsm Jun 03 '20 at 05:09

1 Answers1

0

It happens because you must be streaming live content and the manifest refresh happens periodically, and with each manifest refresh, some of the chunks in the manifest will get removed from the top and some new chunks will get added at the bottom. getCurrentPosition() returns the absolute position of the player for that particular manifest. so it reduces slightly on each manifest refresh.

#EXTM3U
    #EXT-X-VERSION:3
    #EXT-X-TARGETDURATION:7
    #EXT-X-MEDIA-SEQUENCE:8779957
    #EXTINF:6.006,
    index_1_8779957.ts?m=1566416212
    #EXTINF:6.006,
    **index_1_8779958.ts?m=1566416212**. -- current position
    #EXTINF:5.372,
    index_1_8779959.ts?m=1566416212
    #EXT-OATCLS-SCTE35:/DAlAAAAAsvhAP/wFAXwAAAGf+/+AdLfiP4AG3dAAAEBAQAAXytxmQ==
    #EXT-X-CUE-OUT:20.020
    #EXTINF:0.634,
    index_1_8779960.ts?m=1566416212
    #EXT-X-CUE-OUT-CONT:ElapsedTime=0.634,Duration=21,SCTE35=/DAlAAAAAsvhAP/wFAXwAAAGf+/+AdLfiP4AG3dAAAEBAQAAXytxmQ==
    #EXTINF:6.006,
    index_1_8779961.ts?m=1566416212
    #EXT-X-CUE-OUT-CONT:ElapsedTime=6.640,Duration=21,SCTE35=/DAlAAAAAsvhAP/wFAXwAAAGf+/+AdLfiP4AG3dAAAEBAQAAXytxmQ==

after manifest refresh

#EXTM3U
    #EXT-X-VERSION:3
    #EXT-X-TARGETDURATION:7
    #EXT-X-MEDIA-SEQUENCE:8779957
    #EXTINF:6.006,
    **index_1_8779958.ts?m=1566416212**. -- updated current position
    #EXTINF:5.372,
    index_1_8779959.ts?m=1566416212
    #EXT-OATCLS-SCTE35:/DAlAAAAAsvhAP/wFAXwAAAGf+/+AdLfiP4AG3dAAAEBAQAAXytxmQ==
    #EXT-X-CUE-OUT:20.020
    #EXTINF:0.634,
    index_1_8779960.ts?m=1566416212
    #EXT-X-CUE-OUT-CONT:ElapsedTime=0.634,Duration=21,SCTE35=/DAlAAAAAsvhAP/wFAXwAAAGf+/+AdLfiP4AG3dAAAEBAQAAXytxmQ==
    #EXTINF:6.006,
    index_1_8779961.ts?m=1566416212
    #EXT-X-CUE-OUT-CONT:ElapsedTime=6.640,Duration=21,SCTE35=/DAlAAAAAsvhAP/wFAXwAAAGf+/+AdLfiP4AG3dAAAEBAQAAXytxmQ==
Saurabh Kumar
  • 437
  • 1
  • 5
  • 18