2 Replies Latest reply on May 30, 2012 6:55 AM by Pimenov Oleg

    How to play a emded video using OSMF?

    egwyh

      Hi all,

       

      I want to play a emded video using OSMF, the as3 class would be something like this :(of course it does not work)

       

      [SWF(width = "356", height = "356", backgroundColor = "0x000000", frameRate = "12")]
          public class VideoPlayer4 extends Sprite {
              [Embed(source = '../../../../assets/video/TRAILOR 1280x720.mp4', mimeType = 'application/octet-stream')]
              public var vClass : Class;
             
              public function VideoPlayer4() {
                  var mediaFactory:MediaFactory = new DefaultMediaFactory();
                  var mediaElement:MediaElement = mediaFactory.createMediaElement(new vClass());
             
                  mediaPlayer = new MediaPlayer();
                  mediaPlayer.media = mediaElement;
                 
                  var mediaContainer:MediaContainer = new MediaContainer();
                  mediaContainer.addMediaElement(mediaElement);

       

                  mediaContainer.width = 356;
                  mediaContainer.height = 356;
                 
                  addChild(mediaContainer);
              }
          }

       

      I have no idea how to do that, please give me some advice.

      Thanks!!

        • 1. Re: How to play a emded video using OSMF?
          egwyh Level 1

          Hi guys, good news!!

           

          I found a way to play embed flv using Flash Player 10.1, come & try yourself!!

           

          package
          {
              import flash.display.Bitmap;
              import flash.display.Sprite;
              import flash.events.*;
              import flash.media.Video;
              import flash.net.NetConnection;
              import flash.net.NetStream;
              import flash.text.TextField;
              import flash.utils.ByteArray;
             
              public class VideoPlayer6 extends Sprite
              {
                 [Embed(source='../../../../assets/video/video.flv', mimeType='application/octet-stream')]
                 private var flvClass:Class;
                 private var flvData:ByteArray = new flvClass();
                
                 private var connection:NetConnection;
                 private var stream:NetStream;
                 private var video:Video;
                
                 public function VideoPlayer6()
                 {
                    connection = new NetConnection();
                    connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
                    connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
                    connection.connect(null);
                 }
                
                 private function netStatusHandler(event:NetStatusEvent):void {
                    switch (event.info.code) {
                       case "NetConnection.Connect.Success":
                          connectStream();
                          break;
                       case "NetStream.Play.StreamNotFound":
                          trace("NetStream.Play.StreamNotFound");
                          break;
                    }
                 }

                 private function connectStream():void {
                    stream = new NetStream(connection);
                    stream.client = { onMetaData:function(obj:Object):void { } };
                    stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
                    stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
                   
                    video = new Video();
                    video.attachNetStream(stream);
                   
                    stream.play(null);
                    stream.appendBytes( flvData as ByteArray );
                         
                    video.width = 356;
                    video.height = 356;
                   
                    addChild(video);
                 }

                 public function stop():void {
                    if( video != null ) {
                       removeChild(video);
                    }
                      
                    if ( stream != null ) {
                       stream.close();
                       connection.close();
                      
                       stream = null;
                       connection = null;
                    }
                 }
                
                 private function securityErrorHandler(event:SecurityErrorEvent):void {
                    trace("securityErrorHandler: " + event);
                 }
                
                 private function asyncErrorHandler(event:AsyncErrorEvent):void {
                     trace("asyncErrorHandler: " + event);
                 }
              }
          }

          • 2. Re: How to play a emded video using OSMF?
            Pimenov Oleg Level 1

            and how do seek() ??