Quick Load and Play Video

  • AmieCutie
  • Newbie
  • Newbie
  • User avatar
  • Posts: 12

Post 3+ Months Ago

So I'm creating a swf that will load an external mp4 video and play it once. My problem is that once online, the video sometimes is very choppy at the beginning, like it's playing and buffering the same spot. Below is my code for loading in the video, I'd love to know how to fix this so the video loads smoooothly :)

Code: [ Select ]

var connection:NetConnection = new NetConnection();
var vid_obj:Object = new Object();

var vidContainer:MovieClip = new MovieClip();

var vid:Video = new Video(420,278);

connection.connect(null);
var stream = new NetStream(connection);
vid.attachNetStream(stream);

vid_obj.onMetaData = metaData;

stream.client = vid_obj;
stream.play("../assets/videos/rush.mp4");

vidContainer.x = 464;
vidContainer.y = 68;
addChildAt(vidContainer,2);
vidContainer.addChild(vid);

stream.addEventListener(NetStatusEvent.NET_STATUS, NCListener);

function NCListener(e:NetStatusEvent) {
    if (e .info.code == "NetStream.Buffer.Empty") {
        stream.play("../assets/videos/rush.mp4");
    }
}

function metaData(info:Object):void {
    
}

addEventListener(Event.REMOVED_FROM_STAGE, remove, false, 0, true);
  1. var connection:NetConnection = new NetConnection();
  2. var vid_obj:Object = new Object();
  3. var vidContainer:MovieClip = new MovieClip();
  4. var vid:Video = new Video(420,278);
  5. connection.connect(null);
  6. var stream = new NetStream(connection);
  7. vid.attachNetStream(stream);
  8. vid_obj.onMetaData = metaData;
  9. stream.client = vid_obj;
  10. stream.play("../assets/videos/rush.mp4");
  11. vidContainer.x = 464;
  12. vidContainer.y = 68;
  13. addChildAt(vidContainer,2);
  14. vidContainer.addChild(vid);
  15. stream.addEventListener(NetStatusEvent.NET_STATUS, NCListener);
  16. function NCListener(e:NetStatusEvent) {
  17.     if (e .info.code == "NetStream.Buffer.Empty") {
  18.         stream.play("../assets/videos/rush.mp4");
  19.     }
  20. }
  21. function metaData(info:Object):void {
  22.     
  23. }
  24. addEventListener(Event.REMOVED_FROM_STAGE, remove, false, 0, true);
  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Posts: 854

Post 3+ Months Ago

I'm not much of an AS guru, but it looks to me that these lines of code:
ACTIONSCRIPT Code: [ Select ]
function NCListener(e:NetStatusEvent) {
    if (e .info.code == "NetStream.Buffer.Empty") {
        stream.play("../assets/videos/rush.mp4");
    }
}
 
  1. function NCListener(e:NetStatusEvent) {
  2.     if (e .info.code == "NetStream.Buffer.Empty") {
  3.         stream.play("../assets/videos/rush.mp4");
  4.     }
  5. }
  6.  

is telling the player to only play when the buffer is 0. Basically, playing 1 chunk of information at a time. Don't you want a buffer?

Like I said, could be wrong. But I noticed a lot of views on this topic with no replies.
  • AmieCutie
  • Newbie
  • Newbie
  • User avatar
  • Posts: 12

Post 3+ Months Ago

ohhh. I looked up Adobe docs more.

So I would use something like this?

Code: [ Select ]
stream.bufferTime=5;
  • mindfullsilence
  • Professor
  • Professor
  • User avatar
  • Posts: 854

Post 3+ Months Ago

sounds right. Like I said, I don't know much about AS. But I'd say by looking at the logic, that's the direction you'd want to go.

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 6 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.