Search code examples
iphoneobjective-ciosipadhttp-live-streaming

AVPlayer Streaming - Play stream at certain time


Because audio streaming with queues/etc (using Apple's SpeakHere project as an example) is far too complicated for my brain to comprehend, I was thinking about playing streaming music a different way. I have a device that is acting as a "radio station", in that other devices connect to that device via wi-fi and "listen in". So i've implemented cocoaHTTPserver, and what I do is take an MPMediaItem from the iTunes library and put it into the public web folder. I then pass the song URL to the other nearby devices using GameKit. This works great, all of my devices can successfully play the song at the URL of the broadcasting device. My problem is that the stream always starts at the beginning. So if the "radio host device" is 30 seconds in on a song, and then someone connects, the new connection starts the song at the beginning.

So my question is, if I continually pass the current playback time from the host device, to the other devices, if a new device connects to the "stream", is there a way for me on an audio stream using AVPlayer, to set the current plackback time?

So the song 20 seconds in, a new device connects, we tell the new device to start the stream at 20 seconds in. Is that possible?

So i've got this solution working excepting my little problem, and you probably think i'm crazy for doing it this way, but its easier to do it this way than figure out the low level APIs that Apple has for streaming.


Solution

  • I used Matt Galagher's AudioStreamer to play a Mp3 stream. Check this link:

    http://cocoawithlove.com/2008/09/streaming-and-playing-live-mp3-stream.html

    The article begins with:

    This week, I present a sample application that streams and plays an audio file from a URL on the iPhone or Mac

    so it may be helpful.

    This post deals with starting playback at any point in the file (startWithOffsetInSecs):

    http://www.saygoodnight.com/2009/08/streaming-audio-to-the-iphone-starting-at-an-offset/