Skip navigation
tekCorap_
Currently Being Moderated

using netstream appendBytes with mp4 file

Apr 14, 2011 6:26 AM

hi. i am trying to play a mp4 video file with netstream.appendbytes method. but the video down't loading. when i am load a flv video file, the player play the flv video but when i am trying a mp4 video file, don't loading. flv works, but mp4 don't works. why? Please help me!

my code is


import flash.net.URLRequest;
import flash.net.URLStream;
import flash.events.ProgressEvent;
import flash.events.Event;
import flash.utils.ByteArray;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.media.Video;
import flash.events.NetStatusEvent;


var urr:URLRequest;
var urs:URLStream;
var nc:NetConnection;
var ns:NetStream;
var vid:Video;
urr=new URLRequest("http://video.ak.fbcdn.net/cfs-ak-snc6/214988/655/115514355195743_26925.mp4?oh=53935006d42b2db7f970d41f07ab617d&oe=4DA8FD00&__gda__=1302920448_181887f1c8692424282dcc9b072f59a0");
urs=new URLStream();
urs.addEventListener(flash.events.ProgressEvent.PROGRESS,progresHnd);
urs.addEventListener(flash.events.Event.COMPLETE,completeHnd);
urs.addEventListener(flash.events.Event.CLOSE,closeHnd);
urs.addEventListener(flash.events.Event.OPEN,openHnd);
urs.load(urr);


function progresHnd(e:Object):void{
     trace (e);
     var bytes:ByteArray=new ByteArray();
     urs.readBytes(bytes,0,urs.bytesAvailable);
     ns.appendBytes(bytes);
     
     }
     
function closeHnd(e:Object):void{
     trace (e);
     }
     
function completeHnd(e:Object):void{
     trace (e);
     }
     
function openHnd(e:Object):void{
     trace (e);
     nc=new NetConnection();
     nc.connect(null);
     ns=new NetStream(nc);
     vid=new Video();
     vid.attachNetStream(ns);
     ns.play(null);     
     addChild(vid);
     }

 

 
Replies
  • Currently Being Moderated
    Apr 14, 2011 9:22 PM   in reply to tekCorap_

    You cannot play mp4 container directly. If you look into documentation of appendBytes you will see that this method understands FLV headers only. This means that you need to create an FLV header at runtime and append mp4's payload after that.

     

    In any case, this is a very tedious task and you are better off sticking with OSMF framework that does that (it is open source).

     
    |
    Mark as:
  • Currently Being Moderated
    Apr 14, 2011 9:24 PM   in reply to tekCorap_

    Another thing. You are better posting this question on HTTP Dynamic Forum:

     

    http://forums.adobe.com/community/flash/httpdynamicstreaming?view=disc ussions

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 4, 2011 7:07 AM   in reply to Andrei1

    hi andrei1,

     

    is it possible to refine what you mean by "mp4's payload".

     

    writing a standard flv-header (0x46, 0x4C, 0x56, 0x01, 0x05, 0x00, 0x00, 0x00, 0x09) is no problem at all, but what to write next?

    which mp4-boxes are required? i guess "mdat" in some way, obviously.

     

    any additional information / links?

     

    thx

     
    |
    Mark as:
  • Currently Being Moderated
    Nov 4, 2011 10:34 AM   in reply to boidy947

    "is it possible to refine what you mean by "mp4's payload"."

     

    by payload I mean bytes that mp4 codec specific bytes that follow header.

     

    Adobe has documentation (PDF) that describes video file specs. I don't have a link to it ready but you can find it on their site. Again, reverse-engineering OSMF code provides deeper insight in how bytearray may be handled.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points