Skip to main content
Inspiring
August 21, 2014
Pergunta

NetStream doesn't play mp4 packaged with app

  • August 21, 2014
  • 1 resposta
  • 470 Visualizações

I'm using StageVideo to play an h264 encoded mp4 file in an iPhone app. When I package the mp4 file with the app (in the root), the app doesn't play the video at all. When I simply change the video's location to a http location where the exact same file is located, it plays fine.

In other words, the only change I'm making is:

Packaging mp4 in root of app:

var _videoURL:String = "video_h264.mp4" ;

_nc = new NetConnection ( ) ;

_nc.connect ( null ) ;

_ns = new NetStream ( _nc ) ;

_ns.client = this ;

_ns.play ( _videoURL ) ;

...

_stageVideo.attachNetStream ( _ns ) ;

to

Hosting video remotely:

var _videoURL:String = "http://www.myDomain.dk/video_h264.mp4" ;

_nc = new NetConnection ( ) ;

_nc.connect ( null ) ;

_ns = new NetStream ( _nc ) ;

_ns.client = this ;

_ns.play ( _videoURL ) ;

...

_stageVideo.attachNetStream ( _ns ) ;

Does anyone know if there's some restriction when using NetStream that could explain this?

Este tópico foi fechado para respostas.

1 Resposta

August 21, 2014

I think you are supposed to have "app://" at the front of file paths when accessing files included with the app.

So in your example, it would be:

var _videoURL:String = "app://video_h264.mp4";

You can also add a listener for the StatusEvent and in the function for the listener, do a check for "NetStream.Play.StreamNotFound" in the event.info.code property:

if (event.info.code == "NetStream.Play.StreamNotFound") {

     // file not found

}

Another way you should be able to get the path to the video file is using the File.applicationDirectory static property:

var _videoURL:String = File.applicationDirectory.resolvePath("video_h264.mp4").url;

Colin Holgate
Inspiring
August 21, 2014

You can get away with just the relative path. But, do make sure you added the folder with the videos in the General tab.

Another thing to know, you may not get a StageVideoAvailabilityEvent.STAGE_VIDEO_AVAILABILITY, that may have already happened before you start looking for it. In case like that you can get remote videos to work, and local videos will sometimes work. Seems to be  amateur of timing.

The way I worked around that issue was to check the stagevideos before listening for the event. Like this:

if ( stage.stageVideos.length >= 1 ) {

  enableStageVideo();

}else{

  stage.addEventListener(StageVideoAvailabilityEvent.STAGE_VIDEO_AVAILABILITY, _onStageVideoAvailability);

}

That seems reliable. enableStageVideo is just a function to set up the stageVideo variable, and its viewPort.

Inspiring
August 21, 2014

Thanks to both of you. I already had the availability workaround implemented, and I knew from bytesLoaded that the video was being located correctly.

I seem to have solved it by encoding using one of Media Encoder's presets for iPhone. I have no idea which particular setting under that preset makes the difference though.