Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Telling my flash mp3 player to get its song list from an xml file

Guest
Nov 12, 2010 Nov 12, 2010

Hello,

What do I need to put in my code to tell my mp3 player to grab its songs from a folder on my server via an xml doc I outputted from my sql server? (the mp3 player is also on the server).

Thanks in advance! 

Here's my code thus far:

Heres my code:

import flash.events.MouseEvent;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.media.SoundChannel;
import fl.events.SliderEvent;

var myMusic:Sound = new Sound();
var soundFile:URLRequest = new URLRequest("lpwfte.mp3");
var channel:SoundChannel = new SoundChannel();
var sTransform:SoundTransform = new SoundTransform();
var myTimer:Timer = new Timer(100);
var songPosition:Number = 0;
var myContext:SoundLoaderContext = new SoundLoaderContext(5000);

myMusic.load(soundFile, myContext);

myTimer.addEventListener(TimerEvent.TIMER, updateTime);
buttonPlay.addEventListener(MouseEvent.CLICK, playMusic);
btnStop.addEventListener(MouseEvent.CLICK, StopMusic);
sldVolume.addEventListener(SliderEvent.CHANGE, ChangeVolume);
myMusic.addEventListener(Event.COMPLETE, getSongLength);
btnPause.addEventListener(MouseEvent.CLICK, pauseMusic);

function pauseMusic(evt:MouseEvent):void
{
songPosition = channel.position;
channel.stop();
}

function convertTime(millis:Number):String
{
var Minutes:Number = ( millis % (1000*60*60)) / (1000 * 60);
var Seconds:Number = ((millis % (1000*60*60)) % (1000 * 60)) /1000;
if(Minutes < 10)
{
  var displayMinutes:String = "0" + Math.floor(Minutes);
}else
{
  var displayMinutes:String = Math.floor(Minutes).toString();
}
if(Seconds < 10)
{
  var displaySeconds:String = "0" + Math.floor(Seconds);
}else
{
  var displaySeconds:String = Math.floor(Seconds).toString();
}
return displayMinutes + ":" + displaySeconds;
//return (Math.floor(Minutes) + ":" + Math.floor(Seconds));
}

function updateTime(evt:TimerEvent):void
{
lblSongTime.text = convertTime(channel.position);
}

function getSongLength(evt:Event):void
{
lblSongTotalTime.text = convertTime(myMusic.length);
lblSongName.text = myMusic.id3.songName;
lblSongArtist.text = myMusic.id3.artist;
lblSongYear.text = myMusic.id3.year;
}

function ChangeVolume(evt:SliderEvent):void
{

sTransform.volume = sldVolume.value;
channel.soundTransform = sTransform;
}

function StopMusic(evt:MouseEvent):void
{
channel.stop();
songPosition = 0;
}

function playMusic(evt:MouseEvent):void
{


channel = myMusic.play(songPosition);
myTimer.start();
}

TOPICS
ActionScript
582
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Nov 12, 2010 Nov 12, 2010

Search Google for a tutorial using terms like "AS3 XML tutorial".  ANy one of them should show you the code you need to parse the xml data into variables you can use in your code for your mp3 URLRequest value.

Translate
LEGEND ,
Nov 12, 2010 Nov 12, 2010
LATEST

Search Google for a tutorial using terms like "AS3 XML tutorial".  ANy one of them should show you the code you need to parse the xml data into variables you can use in your code for your mp3 URLRequest value.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines