Streaming video using loadWithURL in AVFoundationPlayer

I’ve been trying to create a streaming video player for iOS, as part of a bigger project. Since it’s my first real OF project, I’ve basically been playing around with moviePlayerExample, but soon found out it’s all a little more complicated than I had anticipated. Hope anyone here can help me move forward with this.

The fact that loadWithURL exists alongside loadWithPath inside AVFoundationPlayer gives me hope that what I’m trying to do really is possible. I made a new function called loadMovieWithUrl based of the loadMovie function in iPhoneVideoPlayer, replacing the part about loadWithPath with:

  
NSString *tempURLString = [[[NSString alloc] initWithCString: url.c_str()] autorelease];  
NSURL *loadingUrl = [NSURL URLWithString:tempURLString];  
[(AVFoundationVideoPlayer*)videoPlayer loadWithURL:loadingUrl];  

This gives me the following error:

-[AVAssetReader initWithAsset:error:] Cannot initialize an instance of AVAssetReader with an asset at non-local URL 'http://mirtebecker.nl/movie.mov’’

I’ve been researching the topic mostly on StackOverflow and found something promising here: http://stackoverflow.com/questions/12500408/can-i-use-avfoundation-to-stream-downloaded-video-frames-into-an-opengl-es-textu/12500409#12500409. It might be caused by the fact that AVAssetReader isn’t able to work correctly with AVURLAsset, which if I understand correctly handles HTTP streaming video. Apparently, there’s a new API in iOS6 that uses a different class called AVPlayerItemVideoOutput that does a better job at it.

I’ve tried getting loadWithURL to work using code from that thread, but I understand too little of Objective C to do a good job at it. Also, I’m still wondering if I’m even looking in the right direction here. It might be a little over my head, but I like a challenge.

Any help is appreciated!

hi Mirte,
yes it indeed does look possible.
it will take a bit of messing around with AVFoundationVideoPlayer to get it to work,
but unfortunately i don’t have too much time to get into this atm.
i can start an issue on github for this and get around to it in the near future.

github issue for this is here,
https://github.com/openframeworks/openFrameworks/issues/1741