Forum Flash, Actionscript, PHP e MySQL
play sound da libreria

 
Nuovo Topic   Rispondi    Forum Flash, Actionscript, PHP e MySQL » Actionscript 3.0
Precedente  Successivo 
Autore Messaggio
lozioraffa
nuovo utente
nuovo utente



Registrato: 28/06/10 17:01
Messaggi: 24

MessaggioOggetto: play sound da libreria
Inviato: 10.11.10 | 15:26
Rispondi citando

ciao coach,
ho un problemino con un musicplayer del quale non trovo soluzione.
praticamente io vorrei che la mia musica (song.mp3), si trovasse dentro la libreria e non all'esterno del swf, questo perchè ora si crea un conflitto con altri componenti che spero di risolvere in questo modo.

spero tu sia all'altezza come sempre. ciao e scusami in anticipo se lo script è un pò lungo.

 
Codice:
/*****************************************
             Song Player Code
This is the code that controls the song
player. Here you can add new songs and
update the text to existing songs. The
rest of the code is to control the buttons
on the song player.
*****************************************/

var onSong=0; //Starting song, begins at 0
var songs=new Array();

/******************************************
To add a song, just reuse this template:
songs.push({text:"[TEXT]", file:"[FILE]"});
Update the [TEXT] field with what should be
displayed when the song is playing.
Update the [FILE] field to the absolute or
relative location of the song file.
******************************************/
songs.push({text:"my music", file:"song.mp3"});


//Initialize song player variables and conditions
var backgroundSong=new Sound();
var backgroundSongChannel;
var paused=false;
var pausedPos;
var muted=false;
var normSTransform=new SoundTransform();
normSTransform.volume=1;
var muteTransform=new SoundTransform();
muteTransform.volume=0;

function playSong()
{
    //The playSong function stops the currently playing song and loads song currently on denoted by the variable onSong
    //The initial buffer time for the song is 10 seconds, to adjust this number, change the variable contained in the load function and in the SoundLoaderContext([buffer time])
    if(backgroundSongChannel)
    {
        backgroundSongChannel.stop();
    }
    backgroundSong=new Sound();
    backgroundSong.load(new URLRequest(songs[onSong].file), new SoundLoaderContext(10));
    
    mPlayerText.text=songs[onSong].text; //Update the text
    backgroundSongChannel=backgroundSong.play(); //Start the song
    
    if(muted)
    {
        //Check if it is currently muted, in which case, apply the muteTransform
        backgroundSongChannel.soundTransform=muteTransform;
    }
    
    paused=false;
    pausedPos=0;
    
    stage.addEventListener(Event.ENTER_FRAME, songFinishedFunction);
}

var lastpos;
function songFinishedFunction(event)
{
    //An error-proof method to check if the song has ended, by checking if it is not paused, if the position has changed since the last check, and if the song position is within the ending second of the song and if the song is fully loaded
    if(!paused && lastpos==backgroundSongChannel.position && backgroundSong.length-backgroundSongChannel.position<1000 && backgroundSong.bytesLoaded==backgroundSong.bytesTotal)
    {
        //If the song has ended, play the next song
        nextSongFunction(new Event(Event.SOUND_COMPLETE));
    }
    lastpos=backgroundSongChannel.position;
}
function prevSongFunction(event)
{
    //Play the previous song
    onSong--;
    if(onSong<0)
    {
        onSong=songs.length-1;
    }
    playSong();
}
function nextSongFunction(event)
{
    //Play the next song
    onSong++;
    if(onSong>=songs.length)
    {
        onSong=0;
    }
    playSong();
}
function pauseSongFunction(event)
{
    //Pause the song or resume the song
    if(paused)
    {
        backgroundSongChannel=backgroundSong.play(pausedPos);
        if(muted)
        {
            backgroundSongChannel.soundTransform=muteTransform;
        }
        playImage.gotoAndStop(2);
    } else {
        pausedPos=backgroundSongChannel.position;
        backgroundSongChannel.stop();
        playImage.gotoAndStop(1);
    }
    paused=!paused;
}
function muteFunction(event)
{
    //Mute or unmute the song
    muted=!muted;
    muteImage.gotoAndStop(muted?2:1);
    if(muted)
    {
        backgroundSongChannel.soundTransform=muteTransform;
    } else {
        backgroundSongChannel.soundTransform=normSTransform;
    }
}

//Add the event listeners for the buttons
prevButton.addEventListener(MouseEvent.CLICK, prevSongFunction);
nextButton.addEventListener(MouseEvent.CLICK, nextSongFunction);
pauseButton.addEventListener(MouseEvent.CLICK, pauseSongFunction);
muteButton.addEventListener(MouseEvent.CLICK, muteFunction);

//Auto-play the first song. Remove the next two lines of code if you do not wish to auto-play the background song.
playSong();
playImage.gotoAndStop(2);



grazie
Torna in cima
Profilo Messaggio privato  
Sponsor
Mostra prima i messaggi di:   
Nuovo Topic   Rispondi    Forum Flash, Actionscript, PHP e MySQL » Actionscript 3.0 Tutti i fusi orari sono GMT + 2 ore
Pagina 1 di 1

Discussioni Simili
Topic Autore Forum Risposte Ultimo Messaggio
Nessun nuovo messaggio aggiungere clip in libreria tramite AS suns ActionScript & Server Side 14 24.01.08 | 19:52 Leggi gli ultimi messaggi
suns
Nessun nuovo messaggio sound alexaloisi Flash Generale 3 29.03.10 | 17:46 Leggi gli ultimi messaggi
Coach
Nessun nuovo messaggio UT2004 @ Play.com gush Games 0 20.10.04 | 14:06 Leggi gli ultimi messaggi
gush
Nessun nuovo messaggio sound player malcom Flash Generale 2 17.05.05 | 15:46 Leggi gli ultimi messaggi
malcom
Nessun nuovo messaggio mc con comando play e stop alexaloisi Flash Generale 3 13.03.08 | 10:09 Leggi gli ultimi messaggi
Coach



 
Vai a:  
Non puoi inserire nuovi Topic in questo forum
Non puoi rispondere ai Topic in questo forum
Non puoi modificare i tuoi messaggi in questo forum
Non puoi cancellare i tuoi messaggi in questo forum
Non puoi votare nei sondaggi in questo forum
Non puoi allegare files in questo forum
Non puoi downloadare gli allegati in questo forum



Powered by phpBB © 2001, 2002 phpBB Group - phpBB SEO Designed by coachdesign - © 2003-2005