Current location: Hot Scripts Forums » General Web Coding » Flash & ActionScript » audio streaming - loading external mp3 files


audio streaming - loading external mp3 files

Reply
  #1 (permalink)  
Old 02-23-07, 10:22 PM
mcrob mcrob is offline
Coding Addict
 
Join Date: Jul 2004
Posts: 266
Thanks: 0
Thanked 0 Times in 0 Posts
audio streaming - loading external mp3 files

Hello I am trying to create an audio streaming flash file. I will be using php, flash and mysql.

I have created a music page and if you click on certain artist, the choosen mp3 track will be played . So if you click on
(EG: musicplayer.php?id=2) then it will grab the mp3 link and use that to select the mp3 in the directory and play it. I have googled this and have had a difficult time doing this. I stumbled on this tutorial which introduced "Mediaplayback" I would die to use this component but it askes for the URL of the mp3 track. I would like to know if its possible to create a simple txt (php perferrably) file and it can grab the information from the txt file and store it into the url of the Mediaplayback so then it can playback the mp3 file. If this is possible plz plz reply back. I really need to know this.
Reply With Quote
  #2 (permalink)  
Old 02-26-07, 04:57 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
there are several options on how to do it. They all have 1 thing in common, that is passing the id to the swf object (via flashvars in html, or via LoadVars in flash)

the flashvars works like this:
HTML Code:
<object etc="...">
<param name="flashvar" value="id=<?=$_GET['id'];?>" />
<embed etc="..." ></embed>
</object>
the LoadVars work completely different, as the call a php page from within flash. This page will then send the id to flash. Here's a basic code:
The Flash:
actionscript Code:
  1. var lv = new LoadVars();
  2. lv.load("http://myurl.com/getid.php");
  3. lv.onLoad = function(){
  4.   if(this.id != ""){
  5.     //do stuff with the id
  6.   }else{
  7.     //invalid id specified
  8.   }
  9. };
The php (getid.php):
PHP Code:

<?php
echo "&id=".$_GET['id'];
?>
When you use this, flash now nows what the id is. You can do a very similar thing to retreive the url. There are 2 options:
1. You receive the id in flash, you request another php page which will send the url
2. you automaticly send the url, and forget about the id

both are not that hard to write. The only difference is that you will have to send some extra data to php when you first retrieve the id.
Here's a sample code to get the url instantly:
The Flash:
actionscript Code:
  1. var lv = new LoadVars();
  2. lv.load("http://myurl.com/geturl.php");
  3. lv.onLoad = function(){
  4.   if(this.url != ""){
  5.     // do stuff with the url
  6.   }else{
  7.     // invalid id specified
  8.   }
  9. };
The php (geturl.php):
PHP Code:

<?php
// assuming you are using a textfile with the id corresponding to the line number on which the url is located in a text file:
$contents file("the_url.txt");
if(
array_key_exists($_GET['id'], $contents)){
  echo 
"&url=".$contents[$_GET['id']];
}else{
  echo 
"&url=";
}
Hope this helps you out. if it doesn't let me know, i'll try to explain more. Also take a look at the Loadvars page on livedocs

UnrealEd
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Textfield, CSS stylesheet external loading Flash_Boi Flash & ActionScript 1 03-03-09 06:43 AM
Download not to play a file mp3 from external server Melamania Script Requests 1 12-17-06 05:27 PM
Need Your HelP! Loading Multiple External Text into Multiple Dynamic Text Fields Flash_Boi Flash & ActionScript 2 03-30-06 03:27 PM
Mixing external files wirh internal content in IFRAME DJ Steffo JavaScript 8 12-13-04 01:28 AM
audio streaming xxtruepinoyxx Script Requests 1 05-30-04 06:18 PM


All times are GMT -5. The time now is 06:30 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.