+ // Set audio session to mediaplayback
+ UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
+ AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory),&sessionCategory);
+ AudioSessionSetActive(true);
+#endif
+
+ p_aout->sys->b_started = true;
+
+ p_aout->time_get = TimeGet;
+ p_aout->play = Play;
+ p_aout->pause = Pause;
+ p_aout->flush = Flush;
+ return VLC_SUCCESS;
+}
+
+static void Stop(audio_output_t *p_aout)
+{
+ AudioSessionSetActive(false);
+
+ p_aout->sys->i_played_length = 0;
+ AudioQueueDisposeTimeline(p_aout->sys->audioQueueRef, p_aout->sys->timelineRef);
+ AudioQueueStop(p_aout->sys->audioQueueRef, true);
+ AudioQueueDispose(p_aout->sys->audioQueueRef, true);
+ msg_Dbg(p_aout, "audioqueue stopped and disposed");
+}
+
+#pragma mark -
+#pragma mark actual playback
+
+static void Play(audio_output_t *p_aout, block_t *p_block)
+{
+ AudioQueueBufferRef inBuffer = NULL;
+ OSStatus status;
+
+ status = AudioQueueAllocateBuffer(p_aout->sys->audioQueueRef, p_block->i_buffer, &inBuffer);
+ if (status == noErr) {
+ memcpy(inBuffer->mAudioData, p_block->p_buffer, p_block->i_buffer);
+ inBuffer->mAudioDataByteSize = p_block->i_buffer;
+
+ status = AudioQueueEnqueueBuffer(p_aout->sys->audioQueueRef, inBuffer, 0, NULL);
+ if (status == noErr)
+ p_aout->sys->i_played_length += p_block->i_length;
+ else
+ msg_Err(p_aout, "enqueuing buffer failed (%li)", status);
+ } else
+ msg_Err(p_aout, "buffer alloction failed (%li)", status);
+
+ block_Release(p_block);
+}
+
+void UnusedAudioQueueCallback(void * inUserData, AudioQueueRef inAQ, AudioQueueBufferRef inBuffer) {
+ /* this function does nothing, but needs to be here to make the AudioQueue API happy.
+ * additionally, we clean-up after empty buffers */
+ VLC_UNUSED(inUserData);
+ AudioQueueFreeBuffer(inAQ, inBuffer);
+}
+
+static void Pause(audio_output_t *p_aout, bool pause, mtime_t date)
+{
+ VLC_UNUSED(date);
+
+ if (pause) {
+ AudioQueuePause(p_aout->sys->audioQueueRef);
+ AudioSessionSetActive(false);