tumtumtum / StreamingKit

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

Gapless playback - MP3 streaming (not URL) #217

Open tomaszwojcik opened 9 years ago

tomaszwojcik commented 9 years ago

Hey

I'm trying to perform a gapless streaming via TCP (I'm parsing packets that contain MP3). For that task I've created a custom data source that accepts NSData, and is basically same as STKLocalFileDataSource with the following differences:

Custom constructor:

- (id) initWithData:(NSData *)data {
    if (self = [super init]) {
        self.data = data;

    }
    return self;
}

Changes in the open method:

    stream = CFReadStreamCreateWithBytesNoCopy(kCFAllocatorDefault, _data.bytes, _data.length,
                                               kCFAllocatorDefault);
    length = _data.length;

When I enqueue data sources, the sound is not gapless, there is some kind of error like a micro gap. Moreover, after some time (varies, sometimes 5 seconds, other times 10 seconds) the sound stops playing.

I have checked if this was a network/packet parsing fault and it's not. Instead of queueing the MP3's to STK player I saved the packets data to file and then played the file - everything was smooth and without errors.

Any ideas what am I doing wrong?

RustamKhisamov commented 7 years ago

maybe it can help to somebody. example for local file. ` -(void) audioPlayer:(STKAudioPlayer)audioPlayer didFinishBufferingSourceWithQueueItemId:(NSObject)queueItemId {

QueueID* queueId = (QueueID*)queueItemId;

MPMediaItem *item // yours next song

NSURL *url = [item valueForProperty:MPMediaItemPropertyAssetURL];

[audioPlayer queueDataSource:[STKAudioPlayer dataSourceFromURL:url]
      withQueueItemId:[[QueueID alloc] initWithUrl:queueId.url andCount:queueId.count + 1]];

} `