Skip navigation
Currently Being Moderated

attach XML playlist

Jul 12, 2012 6:30 AM

I'm creating xml player. xml process and playing single video is fine. i stuck at multiple videos playing. give me any solution please..?

 

i have 3 buttons, if i click button_1 play first video, or if i click button_3 play 3rd video.

how to attach videoURL = playlist files.

 

 

var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("video_list.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
 
 function processXML(e:Event):void
{
          myXML = new XML(e.target.data);
          trace(myXML.Video[0]);
}
 
button_1.addEventListener(MouseEvent.CLICK, btn1Click);
button_2.addEventListener(MouseEvent.CLICK, btn2Click);
 
 
function btn1Click(e:MouseEvent):void
{
          ns.play(myXML.Video[0]);
}
 
 
function btn2Click(e:MouseEvent):void
{
          ns.play(myXML.Video[1]);
}
 
var videoURL:String;
//var videoURL:String = "http://www.helpexamples.com/flash/video/cuepoints.flv";
 
var nConnection:NetConnection;
var ns:NetStream;
var video:Video = new Video();
 
nConnection = new NetConnection();
nConnection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nConnection.connect(null);
 
function netStatusHandler(event:NetStatusEvent):void
{
          switch (event.info.code)
          {
                    case "NetConnection.Connect.Success" :
                              connectStream();
                              break;
 
                    case "NetStream.Play.Stop" :
                              break;
                    default :
          }
}
 
 
function connectStream():void
{
          ns = new NetStream(nConnection);
          ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
 
          vidDisplay.attachNetStream(ns);
          ns.play(videoURL);
}
 

 

 

XML


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

<Playlist>

<Video Title="Chapter 1">media/video_1.flv</Video>
<Video Title="Chapter 2">media/video_2.flv</Video>

</Playlist>
 
Replies
  • kglad
    62,158 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 12, 2012 7:16 AM   in reply to Venkom

    you only have code for two buttons and you've got screwy code in your netStatusHandler.

     

    try:

     

     

     

     

     

    var myXML:XML;
    var myLoader:URLLoader = new URLLoader();
    myLoader.load(new URLRequest("video_list.xml"));
    myLoader.addEventListener(Event.COMPLETE, processXML);
     
     function processXML(e:Event):void
    {
              myXML = new XML(e.target.data);
              trace(myXML.Video[0]);
    }
     
    button_1.addEventListener(MouseEvent.CLICK, btn1Click);
    button_2.addEventListener(MouseEvent.CLICK, btn2Click);
     
     
    function btn1Click(e:MouseEvent):void
    {
              ns.play(myXML.Video[0]);
    }
     
     
    function btn2Click(e:MouseEvent):void
    {
              ns.play(myXML.Video[1]);
    }
     
    
     
    var nConnection:NetConnection = new NetConnection();
    nConnection.connect(null);
    var ns:NetStream = new NetStream(nConnection);
    ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

     var video:Video = new Video();

    video.attachNetStream(ns);
    addChild(video);
    function netStatusHandler(event:NetStatusEvent):void { 
    // you have no useful code here
    }

     

     

     
    |
    Mark as:
  • kglad
    62,158 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 12, 2012 9:52 AM   in reply to Venkom

    use:

     

    var videoURL:String;

    var myXML:XML;
    var myLoader:URLLoader = new URLLoader();
    myLoader.load(new URLRequest("video_list.xml"));
    myLoader.addEventListener(Event.COMPLETE, processXML);

    function processXML(e:Event):void
    {
              myXML = new XML(e.target.data);
              trace(myXML.Video[0]);
    }

    button_1.addEventListener(MouseEvent.CLICK, btn1Click);
    button_2.addEventListener(MouseEvent.CLICK, btn2Click);


    function btn1Click(e:MouseEvent):void
    {

    videoURL=myXML.Video[0];
              ns.play(myXML.Video[0]);
    }


    function btn2Click(e:MouseEvent):void
    {

    videoURL=myXML.Video[1];
              ns.play(myXML.Video[1]);
    }



    var nConnection:NetConnection
    = new NetConnection();
    nConnection.connect(null);

    var ns:NetStream
    = new NetStream(nConnection);
    ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

     var video:Video = new Video();

     


    video.attachNetStream(ns);
    addChild(video);
    function netStatusHandler(event:NetStatusEvent):void { 
    // you have no useful code here
    }

     


    play_btn.addEventListener(MouseEvent.CLICK, playClicked);

    pause_btn.addEventListener(MouseEvent.CLICK, pauseClicked);

     

    play_btn.visible = false;

    var videoPaused:Boolean = false;

     

    function playClicked(e:MouseEvent):void{

              if(!videoPaused)

              {

                        ns.play(videoURL);

              }

              else

              {

                        ns.resume();

              }

      play_btn.visible = false;

    }

     

    function pauseClicked(e:MouseEvent):void

    {

              ns.pause();

      play_btn.visible = true;

              videoPaused = true;

    }

     
    |
    Mark as:
  • kglad
    62,158 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 12, 2012 11:30 AM   in reply to Venkom

    everything should work as long as you wait for xml loading to complete before clicking your buttons.  you can disable those buttons when you app starts and enable them in processXML.

     

    var videoURL:String;

    var myXML:XML;
    var myLoader:URLLoader = new URLLoader();
    myLoader.load(new URLRequest("video_list.xml"));
    myLoader.addEventListener(Event.COMPLETE, processXML);

    function processXML(e:Event):void
    {

    button_1.enabled=true;

    button_2.enabled=true;


              myXML = new XML(e.target.data);
              trace(myXML.Video[0]);
    }

    button_1.addEventListener(MouseEvent.CLICK, btn1Click);
    button_2.addEventListener(MouseEvent.CLICK, btn2Click);


    button_1.enabled=false;

    button_2.enabled=false;


    function btn1Click(e:MouseEvent):void
    {

    videoURL=myXML.Video[0];
              ns.play(myXML.Video[0]);
    }


    function btn2Click(e:MouseEvent):void
    {

    videoURL=myXML.Video[1];
              ns.play(myXML.Video[1]);
    }



    var nConnection:NetConnection
    = new NetConnection();
    nConnection.connect(null);

    var ns:NetStream
    = new NetStream(nConnection);
    ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

     var video:Video = new Video();

     


    video.attachNetStream(ns);
    addChild(video);
    function netStatusHandler(event:NetStatusEvent):void { 
    // you have no useful code here
    }

     


    play_btn.addEventListener(MouseEvent.CLICK, playClicked);

    pause_btn.addEventListener(MouseEvent.CLICK, pauseClicked);

     

    play_btn.visible = false;

    var videoPaused:Boolean = false;

     

    function playClicked(e:MouseEvent):void{

              if(!videoPaused)

              {

                        ns.play(videoURL);

              }

              else

              {

                        ns.resume();

              }

      play_btn.visible = false;

    }

     

    function pauseClicked(e:MouseEvent):void

    {

              ns.pause();

      play_btn.visible = true;

              videoPaused = true;

    }

     
    |
    Mark as:
  • kglad
    62,158 posts
    Jul 21, 2002
    Currently Being Moderated
    Jul 13, 2012 6:48 AM   in reply to Venkom

    you're welcome.

     
    |
    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