Skip to main content
May 30, 2011
Question

Help needed with video player.

  • May 30, 2011
  • 1 reply
  • 470 views

Hi there,

I have an issue with my videoplayer i can't seem to fix. When the playVideo functions is called I need to pause the music player. I tried some possibilities but flash keeps giving me an error.

I use this code, can someone tell me what I need to add to pause the music player when the video player starts and let the music continue when the video player closes ?

Thank you very much,

Mathias

var my_songs:XMLList;

var my_total:Number;

var my_sound:Sound;

var my_channel:SoundChannel;

var current_song:Number = 0;

var song_position:Number = 0.1;

var song_paused:Boolean;

var myXMLLoader:URLLoader = new URLLoader();

myXMLLoader.load(new URLRequest("playlist.xml"));

myXMLLoader.addEventListener(Event.COMPLETE, processXML);

function processXML(e:Event):void

{

var myXML:XML = new XML(e.target.data);

my_songs = myXML.SONG;

my_total = my_songs.length();

playSong(0);

myXMLLoader.removeEventListener(Event.COMPLETE, processXML);

myXMLLoader = null;

}

function playSong(mySong:Number):void

{

var myTitle = my_songs[mySong]. @ TITLE;

var myURL = my_songs[mySong]. @ URL;

title_txt.text = myTitle;

if (my_channel)

{

my_channel.stop();

my_channel.removeEventListener(Event.SOUND_COMPLETE, onNext);

}

my_sound = new Sound();

my_sound.load(new URLRequest(myURL));

my_channel = my_sound.play();

my_channel.addEventListener(Event.SOUND_COMPLETE, onNext);

}

next_btn.addEventListener(MouseEvent.CLICK, onNext);

function onNext(e:Event):void

{

current_song++;

if (current_song >= my_total)

{

current_song = 0;

}

playSong(current_song);

}

prev_btn.addEventListener(MouseEvent.CLICK, onPrev);

function onPrev(e:MouseEvent):void

{

current_song--;

if (current_song < 0)

{

current_song = my_total - 1;

}

playSong(current_song);

}

pause_btn.addEventListener(MouseEvent.CLICK, onPause);

function onPause(e:MouseEvent):void

{

if (my_channel)

{

song_position = my_channel.position;

my_channel.stop();

song_paused = true;

}

}

play_btn.addEventListener(MouseEvent.CLICK, onPlay);

function onPlay(e:MouseEvent):void

{

if (song_paused)

{

my_channel = my_sound.play(song_position);

song_paused = false;

}

else if (!my_channel)

{

playSong(current_song);

}

}

//MOVIE PLAYER - MOVIE PLAYER - MOVIE PLAYER - MOVIE PLAYER - MOVIE PLAYER - MOVIE PLAYER - MOVIE PLAYER - MOVIE PLAYER - MOVIE PLAYER - MOVIE PLAYER - MOVIE PLAYER

var activeVideo:String;

//INTROMOVIE

function introMovie()

{

activeVideo = "fotoreeks_1.flv";

playVideo();

}

introMovie();

function playVideo()

{

var BG_black_mc:MovieClip = new BG_black();

addChild(BG_black_mc);

BG_black_mc.x=(BG_black_mc.stage.stageWidth / 2);

BG_black_mc.y=(BG_black_mc.stage.stageHeight / 2);

BG_black_mc.alpha = 0;

TweenLite.to(BG_black_mc,0.5, {alpha:1, ease:Sine.easeOut});

var myVideo:Video = new Video(1280,720);

addChild(myVideo);

myVideo.alpha = 0;

TweenLite.to(myVideo,1, {alpha:1, ease:Sine.easeOut});

myVideo.x=(myVideo.stage.stageWidth / 2) - (myVideo.width / 2);

myVideo.y=(myVideo.stage.stageHeight / 2) - (myVideo.height / 2);

var nc:NetConnection = new NetConnection();

nc.connect(null);

var ns:NetStream = new NetStream(nc);

myVideo.attachNetStream(ns);

myVideo.smoothing = true;

var listener:Object = new Object();

listener.onMetaData = function(evt:Object):void {};

ns.client = listener;

ns.play(activeVideo);

ns.pause();

ns.seek(0);

ns.resume();

var playMovie_btn:SimpleButton = new playMovieBtn();

addChild(playMovie_btn);

playMovie_btn.x = 370;

playMovie_btn.y = 860;

playMovie_btn.scaleX = 0.5;

playMovie_btn.scaleY = 0.5;

playMovie_btn.alpha = 0;

var pauseMovie_btn:SimpleButton = new pauseMovieBtn();

addChild(pauseMovie_btn);

pauseMovie_btn.x = 370;

pauseMovie_btn.y = 860;

pauseMovie_btn.scaleX = 0.5;

pauseMovie_btn.scaleY = 0.5;

pauseMovie_btn.alpha = 0;

TweenLite.to(pauseMovie_btn,1, {alpha:0.9, ease:Sine.easeOut});

var closeMovie_btn:SimpleButton = new closeMovieBtn();

addChild(closeMovie_btn);

closeMovie_btn.x = 1550;

closeMovie_btn.y = 860;

closeMovie_btn.scaleX = 0.5;

closeMovie_btn.scaleY = 0.5;

closeMovie_btn.alpha = 0;

TweenLite.to(closeMovie_btn,1, {alpha:0.9, ease:Sine.easeOut});

setChildIndex(pauseMovie_btn, numChildren - 1);

closeMovie_btn.addEventListener(MouseEvent.MOUSE_DOWN, closeMovie);

pauseMovie_btn.addEventListener(MouseEvent.MOUSE_DOWN, pauseMovie);

function pauseMovie(evt:MouseEvent):void

{

ns.pause();

setChildIndex(playMovie_btn, numChildren - 1);

TweenLite.to(pauseMovie_btn,0.2, {alpha:0, ease:Sine.easeOut});

TweenLite.to(playMovie_btn,0.2, {alpha:0.9, ease:Sine.easeOut});

pauseMovie_btn.removeEventListener(MouseEvent.MOUSE_DOWN, pauseMovie);

playMovie_btn.addEventListener(MouseEvent.MOUSE_DOWN, playMovie);

function playMovie(evt:MouseEvent):void

{

ns.resume();

setChildIndex(pauseMovie_btn, numChildren - 1);

TweenLite.to(pauseMovie_btn,0.2, {alpha:0.9, ease:Sine.easeOut});

TweenLite.to(playMovie_btn,0.2, {alpha:0, ease:Sine.easeOut});

playMovie_btn.removeEventListener(MouseEvent.MOUSE_DOWN, playMovie);

pauseMovie_btn.addEventListener(MouseEvent.MOUSE_DOWN, pauseMovie);

}

}

function closeMovie(evt:MouseEvent):void

{

ns.pause();

TweenLite.to(BG_black_mc,1, {delay:0.5, alpha:0, ease:Sine.easeOut,onComplete:onFinishTween});

TweenLite.to(playMovie_btn,0.2, {alpha:0, ease:Sine.easeOut});

TweenLite.to(pauseMovie_btn,0.2, {alpha:0, ease:Sine.easeOut});

TweenLite.to(closeMovie_btn,0.5, {alpha:0, ease:Sine.easeOut});

TweenLite.to(myVideo,0.5, {alpha:0, ease:Sine.easeOut});

function onFinishTween():void

{

removeChild(BG_black_mc);

removeChild(playMovie_btn);

removeChild(pauseMovie_btn);

removeChild(closeMovie_btn);

removeChild(myVideo);

myVideo.clear();

nc.close();

ns.close();

}

}

}

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
May 30, 2011

You should copy and paste the entire error message in your posting, versus only the relevant portion of the code involved.

May 30, 2011

Hi there Ned,

Oke I'll try to figure out as far as I can, maybe you can help me with an other problem ?

I added a progressbar to my player but i doesn't seem to work, neither is flash giving me an error. Maybe you know what I'm missing ?

I'v posted it as a new discussion.

Thank you,

Mathias