Simultaneously stream and save a video?

edoloughlin picture edoloughlin · May 25, 2009 · Viewed 7.8k times · Source

I'm writing an app, part of which allows the user stream/play videos. I want to restrict the functionality so that they can only stream videos if they have a WiFi connection. I will then save the video so that when they have a 3G only (or lesser) connection they can't stream videos and can only replay videos that are saved on the phone.

Ideally, I'd like to get MPMoviePlayerController to stream/play the movie and then access the movie data and save it. However, the MPMoviePlayerController api doesn't seem to support access to the movie data.

I'd like to avoid and download-then-play scenario. Any ideas?

Answer

Johan Carlsson picture Johan Carlsson · Oct 7, 2009

Two solutions come to mind. Both this solutions require that the file is in a format that can be played progressive, e.g. that you don't need the whole file to be able to play it (but that would be a prerequisite anyway).

  1. use a thread to download the data and append it to a file, and play the file from another thread. Now, that requires that you can handle EOF events in the MPMoviePlayerController and pause the playing until the cache file is appended to and then resume for the same point.

So far what I've seen people doing this it doesn't work because MPMoviePlayerController can't handle the EOF event. (not tested it my self yet) [Caching videos to disk after successful preload by MPMoviePlayerController

  1. Skip the playing from a file and setup a local HTTP server and stream from that (on localhost). This is also not tested. The idea is that MPMoviePlayerController would handlle the event of missing data better from a HTTP stream then from reading the file directly. Downside might be that it is less efficient, but I think that is a minor increase in CPU. I don't know if the network interface would handle it, but I'm assuming it's not an issue.

I leave this answer as a wiki, because I don't have a working solution but I too want one.