I have a project I’m working where I need a single media player to be able to play either audio or video depending on what gets passed (flv or m4a).
Here’s the code I have so far:
ExternalInterface.addCallback("playMedia", playMedia); // The way a/v gets changed is from a dropdown menu in the HTML
var av:String; // The param that gets passed to my playMedia function which will determine if its audio or video
var nc:NetConnection = new NetConnection();
nc.connect(null);
var ns:NetStream = new NetStream(nc);
ns.client(this);
function playMedia(av:String):void {
var container:Sprite = new Sprite(); // container to add the a/v to
if(av.match(".flv")) // if it's a video, do the following
{
var video:Video = new Video(); // this makes it so we can actually see our video
video.attachNetStream(ns);
container.addChild(video); // add video to the container
parent.addChild(container); // add container to the stage
video.x = 110;
video.y = 90;
ns.play(av);
}
if(av.match(".m4a")) // if it's audio, do the following
{
/* Here's where my problem is. How do I add the audio
to the container in such a way that it 'replaces' the video
that's in the container? I may want to add a static image as a visual representation.*/
ns.play(av);
}
}