Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix playback after seek #329

Merged
merged 1 commit into from
May 10, 2017
Merged

Fix playback after seek #329

merged 1 commit into from
May 10, 2017

Conversation

derpoliuk
Copy link
Collaborator

@derpoliuk derpoliuk commented Mar 28, 2017

Use estimated byte offset (if available) instead of calculated byte offset (Close #273).

Issue

I create STKAudioPlayer with URL to mp3 file. File duration is 38:05 (2285 s). After seeking to 37:40 (2260 s), player stopped.

Solution

After debugging player I figured out that offset is missing after seek: 6d00aa0#diff-b23113711075e5d630996cbb4e38dfe7L1500

I guess it was a typo and I removed ! before (ioFlags & kAudioFileStreamSeekFlag_OffsetIsEstimated). But this caused another issue: seek started working as expected, but progress was off.

For example after seeking to 37:40 (2260 s), progress was 37:15 (2235 s), not 37:40 (2260 s). The difference was exact value of delta variable. So I removed this code and now it works as expected.

Important

I test this code only with mp3 files and I don't know how it'll work with other formats.

Use estimated byte offset (if available) instead
of calculated byte offset
@derpoliuk
Copy link
Collaborator Author

@tumtumtum I updated commit and PR's description.

@tumtumtum tumtumtum merged commit a32ba73 into tumtumtum:master May 10, 2017
@chuckkreuser
Copy link

@derpoliuk I've been stuck on this for a while when trying to stream mp3s. I'm glad your fix works for you. I tried and it's still the broken for me.

I'm curious, how are you instantiating the player? I've tried { .flushQueueOnSeek = YES } and { .gracePeriodAfterSeekInSeconds = 5.0f } but no luck.

Also, are you just calling play or queueing your mp3s? I'm not sure if that would make a difference, just trying different things.

Thanks

@derpoliuk
Copy link
Collaborator Author

@chuckkreuser, I've been stuck on this for a while when trying to stream mp3s.

I didn't try mp3s, only mp3.

I'm curious, how are you instantiating the player?

static func player(withDelegate delegate: STKAudioPlayerDelegate) -> STKAudioPlayer {
    let player = STKAudioPlayer(options: (STKAudioPlayerOptions(flushQueueOnSeek: true, enableVolumeMixer: false, equalizerBandFrequencies: (50, 100, 200, 400, 800, 1600, 2600, 3200, 4800, 5600, 6400, 7200, 8200, 9200, 11200, 12800, 13200, 14200, 15000, 15600, 16400, 17200, 18200, 1900), readBufferSize: 0, bufferSizeInSeconds: 30, secondsRequiredToStartPlaying: 0.5, gracePeriodAfterSeekInSeconds: 0.5, secondsRequiredToStartPlayingAfterBufferUnderun: 0.5)))
    player.meteringEnabled = true
    player.volume = 1
    player.delegate = delegate
    return player
}

I'm glad your fix works for you. I tried and it's still the broken for me.

This change did fix seek on some files, but on other files playback was really broken after seek - I hear only loud noice instead of audio file.

I tried to fix it and reverted back to previous version.

@chuckkreuser
Copy link

@derpoliuk Ah I see, thanks for your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants