0 Replies Latest reply: Jul 2, 2013 1:03 AM by ramashish13 RSS

    How to set source in VideoPlayer via actionscript?

    ramashish13

      Hi,

       

      I'm trying to play video in spark.components.VideoPlayer by setting its source property. However, on playing the video doesn't play and comes out as garbled. Am I missing something here?

       

      Here is the source code-

       

      <?xml version="1.0" encoding="utf-8"?>

      <!-- controls\videoplayer\VideoPlayerEvent.mxml-->

      <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"

                             xmlns:s="library://ns.adobe.com/flex/spark"

                             xmlns:mx="library://ns.adobe.com/flex/mx">

          <s:layout>

              <s:VerticalLayout/>

          </s:layout>

          <fx:Script>

              <![CDATA[

                  import org.osmf.events.MediaPlayerStateChangeEvent;

                  import org.osmf.events.TimeEvent;

                  import spark.components.VideoPlayer;

                 

                  protected function vpCompleteHandler(event:TimeEvent):void {

                      myTA.text = "Video complete - restarting."

                  }

                  protected function

                      vpMediaPlayerStateChangeHandler(event:MediaPlayerStateChangeEvent):void {

                      if (event.state == "loading")

                          myTA.text = "loading ...";

                      if (event.state == "playing")

                          myTA.text = "playing ...";

                  }

                 

                  private function onPlayVideo(): void {

                      videoPlayer = new VideoPlayer();

                      videoPlayer.source = "file:///D:/shared/work/data/test/original/bkb2.flv";

                      playerContainer.addElement(videoPlayer);

                      //player.

                  }

                  private function onStopVideo(): void {

                      videoPlayer.stop();

                  }

       

                  private var videoPlayer:VideoPlayer;

              ]]>

          </fx:Script>

          <s:VGroup id="playerContainer" verticalAlign="middle">

          </s:VGroup>

          <s:HGroup>

              <s:TextArea id="myTA" width="350" height="25"/>

              <s:Button label="Play Video" click="onPlayVideo();"/>       

              <s:Button label="Stop Video" click="onStopVideo();"/>       

          </s:HGroup>

         

      </s:WindowedApplication>

       

      Thanks in advance,

      Ramashish