Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

byjoe

[Resolvido] Flash Player + XML = tocar de um folder ou tocar dire

Recommended Posts

Bem amigos, desculpem-me se esta não for a área para postar esta dúvida.

Procurei pelo fórum o que estou precisando e não encontrei.

Não tenho experiência com programação e meu problema é que tenho um flash player que toca arquivos mp3 de uma pasta local do meu site.

Está funcionando perfeitamente, mas gostaria que ele tocasse, além dos arquivos da pasta, um arquivo de uma URL específica, no caso o arquivo de outro site: http://audio.climatempo.com.br/radios/es.mp3

 

 

Abaixo segue os códigos do Flash:

import mx.transitions.Tween;
import mx.transitions.easing.*;

var song_folder:String = "songs/";
var song_list:Array = new Array();
var track_list:Array = new Array();
var artist_list:Array = new Array();
var album_list:Array = new Array();
var current:Number = 0;
var position:Number;
var new_volume:Number = 100;

var flashmo_xml:XML = new XML();
flashmo_xml.ignoreWhite = true;
flashmo_xml.onLoad = function()
{
	var nodes:Array = this.firstChild.childNodes;
	for(var i = 0; i < nodes.length; i++)
	{
		song_list.push(nodes[i].attributes.filename);
		track_list.push(nodes[i].attributes.track);
		artist_list.push(nodes[i].attributes.artist);
		album_list.push(nodes[i].attributes.album);
	}
	play_song("start");
}
flashmo_xml.load(song_folder + "flashmo_songs.xml");

fm_play.play_pause.onRelease = function()
{
	if( this._parent._currentframe == 1 )
		this._parent._parent.play_pause("pause");
	else
		this._parent._parent.play_pause("play");
	
	this._parent.play();
}
fm_prev.onRelease = function()
{
	this._parent.play_song("prev");
}
fm_next.onRelease = function()
{
	this._parent.play_song("next");
}
function play_song(track:String):Void
{
	if(track == "prev")
		current--;
	else if(track == "start")
		current = 0;
	else
		current++;
		
	if(current == song_list.length)
		current = 0;
	else if(current < 0)
		current = song_list.length - 1;
	
	s = new Sound(); s.loadSound(song_folder + song_list[current], true);
	s.setVolume(new_volume);
	track_title.text = track_list[current];
	artist_name.text = artist_list[current];
	album_title.text = album_list[current];
	track_info.text = "Track " + (current+1) + " of " + song_list.length;
	fm_play.gotoAndStop(1);
}
function play_pause(pp:String):Void
{
	if(pp == "pause")
	{
		position = s.position;
		s.stop();
	}
	else if(pp == "play")
	{
		s.start(position/1000);
	}
}
var my_interval:Number;
my_interval = setInterval(update_bar, 100);
function update_bar():Void 
{
	var total_seconds:Number = s.duration/1000;
	var minutes:Number = Math.floor(total_seconds/60);
	var seconds = Math.floor(total_seconds)%60;
	if(seconds < 10) 
		seconds = "0" + seconds;
		
	var total_current_seconds:Number = s.position/1000;
	var current_minutes:Number = Math.floor(total_current_seconds/60);
	var current_seconds = Math.floor(total_current_seconds)%60;
	if(current_seconds < 10) 
		current_seconds = "0" + current_seconds;
	
	percent_loaded = Math.round(s.getBytesLoaded() / s.getBytesTotal() * 100);
	
	if( percent_loaded != 100 && percent_loaded > 0)
		loading_info.text = "loading... " +  percent_loaded + "%";
	else
		loading_info.text = "";
		
	flashmo_bar._width = Math.round( s.position/s.duration*flashmo_bar_bg._width );
	flashmo_pointer._x = flashmo_bar._width + flashmo_bar._x;
		
	position_info.text = current_minutes +":"+ current_seconds + " / " + minutes +":"+ seconds;
	if( s.getBytesLoaded() == s.getBytesTotal() && s.position == s.duration )
		play_song();
}
var theMenu:ContextMenu = new ContextMenu();
theMenu.hideBuiltInItems(); _root.menu = theMenu;
var item:ContextMenuItem = new ContextMenuItem("Created by www.byjoe.com", flashmo);
theMenu.customItems[0] = item;
function flashmo() {	getURL("http://www.byjoe.com");	}

flashmo_pointer.onPress = function()
{
	this.startDrag(true, flashmo_bar_bg._x, this._y, flashmo_bar_bg._width + flashmo_bar_bg._x, this._y );
	s.stop(); clearInterval(my_interval);
}
flashmo_pointer.onRelease = flashmo_pointer.onReleaseOutside = function()
{
	this.stopDrag();
	new_position = s.duration * (this._x - flashmo_bar_bg._x) / (flashmo_bar_bg._width * 1000);
	s.start(new_position); fm_play.gotoAndStop(1);
	my_interval = setInterval(update_bar, 100);
}
flashmo_volume_pointer.onPress = function()
{
	this.startDrag(true, flashmo_volume_bg._x, this._y, flashmo_volume_bg._width + flashmo_volume_bg._x, this._y );
}
flashmo_volume_pointer.onRelease = flashmo_volume_pointer.onReleaseOutside = function()
{
	this.stopDrag(); new_volume = this._x - flashmo_volume_bg._x;
	new Tween(flashmo_volume, "_width", Strong.easeOut, flashmo_volume._width, new_volume, 1.5, true);
	s.setVolume(new_volume);
}

Já o arquivo XML traz os seguintes códigos:

<?xml version="1.0" encoding="UTF-8" ?>
<songs>

	<song filename="Gary_Hoey_the_first_noel.mp3" track="Track One [www.neverrain.com]" artist="Gary Hoey" album="The First Noel" />
	<song filename="Fastway_Say_What_You_Will.mp3" track="Track Two [www.neverrain.com]" artist="Fastway" album="Say What You Will" />
	<song filename="Bob_Marley_Easy_Skanking.mp3" track="Track Three [www.neverrain.com]" artist="Bob Marley" album="Easy Skanking" />
	<song filename="Dick_Dale_Misirlou.mp3" track="Track Four [www.neverrain.com]" artist="Dick Dale" album="Misirlou" />

</songs>

Alguém poderia me dar um help nisso?

 

Desde já, muito obrigado pela atenção.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Simples...

 

Remove a variavel song_folder daqui:

s.loadSound(song_folder + song_list[current], true);

E ai adiciona o folder da musica no filename no XML

E se quiser tocar uma url basta colocar a url no filename

 

Ficando assim seu XML no caso:

<?xml version="1.0" encoding="UTF-8" ?>
<songs>

 <song filename="song/Gary_Hoey_the_first_noel.mp3" track="Track One [www.neverrain.com]" artist="Gary Hoey" album="The First Noel" />
 <song filename="song/Fastway_Say_What_You_Will.mp3" track="Track Two [www.neverrain.com]" artist="Fastway" album="Say What You Will" />
 <song filename="song/Bob_Marley_Easy_Skanking.mp3" track="Track Three [www.neverrain.com]" artist="Bob Marley" album="Easy Skanking" />
 <song filename="song/Dick_Dale_Misirlou.mp3" track="Track Four [www.neverrain.com]" artist="Dick Dale" album="Misirlou" />
 <song filename="http://www.site.com/musica.mp3" track="Track da minha musica" artist="Artista da minha musica" album="Album da minha musica" />
</songs>
Abraços

Compartilhar este post


Link para o post
Compartilhar em outros sites

Simples...

 

Remove a variavel song_folder daqui:

s.loadSound(song_folder + song_list[current], true);

Caramba, muito obrigado Berseck, funcionou perfeitamente! Eu estava tentando no local errado:

flashmo_xml.load(song_folder + "flashmo_songs.xml");

Fora as quebradas de cabeça tentando colocar variável a mais de URL e tals!

 

Mais uma vez obrigado!

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.