Skip to main content
June 17, 2011
Answered

Save h.264 video, load to StageWebView

  • June 17, 2011
  • 2 replies
  • 1201 views

is it possible to load a video and save it to the file system,

then load it back in and play it in stageWebView?

When i load the saved video, it is in byteArray format.

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer blazejewicz

Hi,

assuming that you've access to raw bytes (that would be best if you receive data asynchronously) I think that you could certainly save data into app storage directory (it lies within application data sandbox on iOS) in a way like:

var file:File = File.applicationStorageDirectory.resolvePath("myVideo.mp4");

then open FileStream and write that data as it arrives (or all at once).

Once you have that file created you could:

- load it directly as discussed here:

http://forums.adobe.com/message/3694991#3694991

- load it via thin "html" hosting web page (you would have to create that thin html hosting page for that video file as well):

http://sonnati.wordpress.com/2011/04/26/air-2-6-for-ios-and-video-playback/

(both solutions require StageWebView as you noted)

hth,

regards,

Peter

2 replies

blazejewiczCorrect answer
Participating Frequently
June 17, 2011

Hi,

assuming that you've access to raw bytes (that would be best if you receive data asynchronously) I think that you could certainly save data into app storage directory (it lies within application data sandbox on iOS) in a way like:

var file:File = File.applicationStorageDirectory.resolvePath("myVideo.mp4");

then open FileStream and write that data as it arrives (or all at once).

Once you have that file created you could:

- load it directly as discussed here:

http://forums.adobe.com/message/3694991#3694991

- load it via thin "html" hosting web page (you would have to create that thin html hosting page for that video file as well):

http://sonnati.wordpress.com/2011/04/26/air-2-6-for-ios-and-video-playback/

(both solutions require StageWebView as you noted)

hth,

regards,

Peter

June 20, 2011

Excellent! That worked, Thank you.

Here is what i did:

1) Load video:

     var urlLoader = new URLLoader();

     urlLoader.dataFormat = URLLoaderDataFormat.BINARY;

     urlLoader.addEventListener(ProgressEvent.PROGRESS, onStageVideoProgress);

     urlLoader.addEventListener(Event.COMPLETE, onStageVideoLoadComplete);

     urlLoader.load(new URLRequest("http://pathToMyVideo/myVideo.mov"));

2) Save the video:

     var file:File = File.documentsDirectory.resolvePath("myVideo.mov")

     var fileStream:FileStream = new FileStream();

     fileStream.openAsync(file, FileMode.WRITE);

     fileStream.addEventListener(ProgressEvent.PROGRESS, onStageVideoSaveProgress);

     fileStream.addEventListener(Event.CLOSE, onStageVideoSaveClose);

     fileStream.addEventListener(Event.COMPLETE, onStageVideoSaveComplete);

     fileStream.addEventListener(IOErrorEvent.IO_ERROR, onStageVideoSaveError);

     fileStream.writeBytes(stageVideoURLLoader.data);

     fileStream.close();

3) Load the saved video to stageWebView:

     var stageWebView:StageWebView = new StageWebView();

     stageWebView.stage = this.stage;

     stageWebView.viewPort = new Rectangle(0, 0, 100, 100);

     var file:File = File.documentsDirectory.resolvePath("myVideo.mov")

     stageWebView.loadURL(file.url);

Simple enough.