tumtumtum / StreamingKit

A fast and extensible gapless AudioPlayer/AudioStreamer for OSX and iOS (iPhone, iPad)
Other
2.42k stars 523 forks source link

Start playback from offset? #307

Open daria-kopaliani opened 7 years ago

daria-kopaliani commented 7 years ago

What is the rightmost way to start streaming file from an offset? Should I subclass STKDataSource or is there an easier way?

derpoliuk commented 7 years ago

I'd do it this way (code in Swift):

let player = ... // create player
let url = ... 
let dataSource = STKAudioPlayer.dataSource(from: url)
player.queue(dataSource, withQueueItemId: SampleQueueId(url: url, andCount: 0))
player.seek(toTime: 42)
self.player = player // to keep strong reference to player

It should work. But if it won't work, then I'd move player.seek(toTime: 42) to -(void) audioPlayer:(STKAudioPlayer*)audioPlayer didStartPlayingQueueItemId:(NSObject*)queueItemId; method of STKAudioPlayerDelegate.