ios problem: using audioqueue to change the playing value
Recentlly, I make a music player with audioqueue (not using avplayer ), the player plays local audio files but not the internet files.Now I want to achieve a function that user could change the playing progress with slider.How can I do? In short, how can I use audioqueue to achieve to slide playing progress when it play local file.
Wish your answer with some important code!
---------------------------Append-----------------------
I modify the codes in demo of audio streamer(URL:http://code4app.net/ios/Audio-Streamer/5019d9066803faa344000000), My thinking is as follows in rough:
1、open the stream with a local music file.
2、Create a AudioFileStreamID Obj (audioFileStream).
3、Create queue in the callback ASPacketsProc.
4、After createqueue, then filled the buffers of the queue in the callback ASPacketsProc.
5、At last, I will call the function to start to play.
Some codes is as followings:
- (void) openReadStream {
CFURLRef urlPath = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, (CFStringRef)filePath, kCFURLPOSIXPathStyle, false);
stream = CFReadStreamCreateWithFile(kCFAllocatorSystemDefault, urlPath);
if (CFReadStreamOpen(stream))
{
CFStreamClientContext context = {0, self, NULL, NULL, NULL};
CFReadStreamSetClient(
stream,
kCFStreamEventHasBytesAvailable | kCFStreamEventErrorOccurred | kCFStreamEventEndEncountered,
ASReadStreamCallBack,
&context);
CFReadStreamScheduleWithRunLoop(stream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
}
}
static void ASReadStreamCallBack (CFReadStreamRef aStream, CFStreamEventType eventType,void* inClientInfo)
{
AudioStreamer* streamer = (AudioStreamer *)inClientInfo;
[streamer handleReadFromStream:aStream eventType:eventType];
}
AudioFileStreamOpen(self,ASPropertyListenerProc,ASPacketsProc,fileTypeHint,&audioFileStream);
- (void)createQueue {
sampleRate = asbd.mSampleRate;
packetDuration = asbd.mFramesPerPacket / sampleRate;
// create the audio queue
AudioQueueNewOutput(&asbd, ASAudioQueueOutputCallback, self, NULL, NULL, 0, &audioQueue);
// listen to the "isRunning" property
AudioQueueAddPropertyListener(audioQueue, kAudioQueueProperty_IsRunning, ASAudioQueueIsRunningCallback, self);
// get the packet size if it is available
UInt32 sizeOfUInt32 = sizeof(UInt32);
AudioFileStreamGetProperty(audioFileStream, kAudioFileStreamProperty_PacketSizeUpperBound, &sizeOfUInt32, &packetBufferSize);
for (unsigned int i = 0; i < kNumAQBufs; ++i)
{
AudioQueueAllocateBuffer(audioQueue, packetBufferSize, &audioQueueBuffer[i]);
}
}
AudioQueueEnqueueBuffer(audioQueue, fillBuf, packetsFilled, packetDescs);
AudioQueueStart(audioQueue, NULL);
I suppose, you used
MPMusicPlayerController
class. If you need some code, you must give some data or code too. I don't know, what class you are using...Though, if you used this, then you can set currentPlaybackTime property, when slider changes.
Let's say, you have this instance:
Then, probably, you can change play time like this: