Jump to content

How do I play an mp3 file from a URL onto a prim? (not video, just mp3)


Domitan Redenblack
 Share

You are about to reply to a thread that has been inactive for 4271 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Normally you will play music on a parcel you own or control.   Here is how you do that:

What is that music I hear?

http://virtualoutworlding.blogspot.com/2012/04/kit-what-is-that-music-i-hear.html

Where people run into problems is that you must use a url that is set up to stream music.   A url to a web page will not work.  Here are instructions for getting the correct url for shoutcast:

Guide to streaming audio. Shoutcast. 2012

http://virtualoutworlding.blogspot.com/2012/04/kit-guide-to-streaming-audio-shoutcast.html

You can play music from a prim using BOP technology:

Hear/see music/video media/BOP in Second Life 2012

http://virtualoutworlding.blogspot.com/2012/04/kit-media-hearsee-musicvideo-mediabop.html

You could even wear a BOP prim, so you would not be limited to playing the music on land you control.  Remember, thouigh, that a BOP prim is a web page, so you would play the music as you would from a web page, by clicking on the correct button   

TKR

 

Link to comment
Share on other sites


Thinkerer Melville wrote: 

You could even wear a BOP prim, so you would not be limited to playing the music on land you control.  Remember, thouigh, that a BOP prim is a web page, so you would play the music as you would from a web page, by clicking on the correct button   

 

I *not* want to play parcel music, thanks. I want to create a HUD which plays an mp3 file. Does the mp3 need to be embedded in a web page?

 

Link to comment
Share on other sites

If you wear a BOP, it will act much like a HUD, except that other people can see it--and can hear the music if they have their preferences set for that.  A BOP is simply a live web page on a prim, so you would have to go to a web page that offers the music  you want.   I have no info about combining a BOP with a HUD or making a HUD  to play mp3s fom the web 

TKR

 

Link to comment
Share on other sites

I *not* want to play parcel music, thanks. I want to create a HUD which plays an mp3 file. 

Does the mp3 need to be embedded in a web page?

 

No,  you may enter directly the URL of the mp3 file if you wish .

Nevertheless , only mp3 is recognized directly in this way . The Ogg format  are not played .

To add , you could n t advance the position in the mp3 file .

If you want to be able to advance forward and backward , the best way  is to use a flash as the player of yahoo or the player of google

Link to comment
Share on other sites

For  http://grooveshark.com/#!/ , this intenal browser is already unable to play the sounds .

If the internal browser  can t , your media on prim can t . 

QTWebkit has not been updated . And even in its last version , QTwebkits is late for the actual standars of HTML .

Some sites play mp3 now with HTML5 balises . They are unknown for the intrenal viewer . So for the medias on prim too .

 

But let s do a simple :

 

go to http://mp3.com who promotes some artists .

Choose a song you like  , right click on the play button and copy url .

You will have for instance 

http://freedownloads.last.fm/download/34369868/Modern%2BMystery.mp3

 

 

1st way : you may directly set the url of the media on prim with this URL

advantage : no conflict with several technologies 

disavandtage : can t know when the song song has finished to play

 

2nd way : 

go for instance to 

http://www.strangecube.com/audioplay/

Paste the url of your mp3 . choose the other options if you wish ( autoplay and all these things )

Copy the embedding code

You will have some kind of code as it 

<!-- Generated by AudioPlay Online Generator (http://www.strangecube.com/audioplay/) --><div><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" width="30" height="30"><PARAM NAME=movie VALUE="http://www.strangecube.com/audioplay/online/audioplay.swf?file=http://freedownloads.last.fm/download/411799275/Wind+In+Her+Hair.mp3&auto=yes&sendstop=yes&repeat=2&buttondir=http://www.strangecube.com/audioplay/online/alpha_buttons/negative&bgcolor=0xffffff&mode=playpause"><PARAM NAME=quality VALUE=high><PARAM NAME=wmode VALUE=transparent><embed src="http://www.strangecube.com/audioplay/online/audioplay.swf?file=http://freedownloads.last.fm/download/411799275/Wind+In+Her+Hair.mp3&auto=yes&sendstop=yes&repeat=2&buttondir=http://www.strangecube.com/audioplay/online/alpha_buttons/negative&bgcolor=0xffffff&mode=playpause" quality=high wmode=transparent width="30" height="30" align="" TYPE="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object></div><!-- End of generated code -->

 

 

Go to your favourite editor and replace all the double quotes by simple quote  ( or escape them from " to \" )

 

 

 

You will have some kind of code as it 

<!-- Generated by AudioPlay Online Generator (http://www.strangecube.com/audioplay/) --><div><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0' width='30' height='30'><PARAM NAME=movie VALUE='http://www.strangecube.com/audioplay/online/audioplay.swf?file=http://freedownloads.last.fm/download/411799275/Wind+In+Her+Hair.mp3&auto=yes&sendstop=yes&repeat=2&buttondir=http://www.strangecube.com/audioplay/online/alpha_buttons/negative&bgcolor=0xffffff&mode=playpause'><PARAM NAME=quality VALUE=high><PARAM NAME=wmode VALUE=transparent><embed src='http://www.strangecube.com/audioplay/online/audioplay.swf?file=http://freedownloads.last.fm/download/411799275/Wind+In+Her+Hair.mp3&auto=yes&sendstop=yes&repeat=2&buttondir=http://www.strangecube.com/audioplay/online/alpha_buttons/negative&bgcolor=0xffffff&mode=playpause' quality=high wmode=transparent width='30' height='30' align='' TYPE='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object></div><!-- End of generated code -->

 

Encloded your string with the strings "<html><body>" and  "</body></html>"

 

Create one script to serve the page in the media of prim

For instance

string html_base; // Our playlist : a strided list with 3 elements : the url of the mp3 , the title of the track, the name of the artis
// Maybe it will be safer to verify the special characters , quotes and all these things. not testedlist g_playlist =[ "http://freedownloads.last.fm/download/30892127/Galanteria.mp3", "Galanteria", "Muchi" , "http://freedownloads.last.fm/download/411799275/Wind%2BIn%2BHer%2BHair.mp3", "Wind in her hair", "Motorama", "http://freedownloads.last.fm/download/1589252/Hahahaczyk.mp3", "Hahahaczyk", "Akurat", "http://freedownloads.last.fm/download/62581279/Cidad%25C3%25A3o%2Bde%2BPapel%25C3%25A3o.mp3", "Cidadao de Papelao" , "O Teatro Magico", "http://freedownloads.last.fm/download/38422548/What%2527s%2BWrong%2BWith%2BMe%2B%2528Nouvelle%2BVague%2BRemix%2529.mp3", "What s Wrong With Me", "Skye", "http://freedownloads.last.fm/download/14320335/Etrezomp-ni%2BKelted.mp3", "Etrezomp-ni Kelted", "Omnia", "http://freedownloads.last.fm/download/120677617/Rock%2527n%2527roll%2BHall%2BOf%2BFame.mp3", "Rock n roll Hall Of Fame", "pornophonique", "http://freedownloads.last.fm/download/100653832/All%2BMy%2BPain.mp3", "All My Pain", "Otklonenie" ];
//We could copy paste the embeded code drectly in the string of the html page .
// But this function will help us to avoid to have to rewrite the same html code several times
// if we need several players in the same page
// Note it s not lever to have a lot of flash in the same page .
// Generally we change them dynamically with some javascript and an anchor
// INPUT : urlMP3 the url of the mp3 to send as paremeter for the flash object
// OUTPUT : a fragment of html code containing the flash player with tthe url of the mp3string generateEmbededObject(string urlMP3){ // <!-- Generated by AudioPlay Online Generator (http://www.strangecube.com/audioplay/) --> return " <div><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0' width='30' height='30'><PARAM NAME=movie VALUE='http://www.strangecube.com/audioplay/online/audioplay.swf?file="+ llEscapeURL(urlMP3)+ "&auto=yes&sendstop=yes&repeat=2&buttondir=http://www.strangecube.com/audioplay/online/alpha_buttons/negative&bgcolor=0xffffff&mode=playstop'><PARAM NAME=quality VALUE=high><PARAM NAME=wmode VALUE=transparent><embed src='http://www.strangecube.com/audioplay/online/audioplay.swf?file="+ llEscapeURL(urlMP3) +"&auto=yes&buttondir=http://www.strangecube.com/audioplay/online/alpha_buttons/negative&bgcolor=0xffffff&mode=playstop' quality=high wmode=transparent width='30' height='30' align='' TYPE='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object></div>" ;//<!-- End of generated code -->}
// this function returs the html page as string
// INPUT : urlMedia : the url served by the prim
// playList : a strided list of 3 elements , url of the mp3 to send as parameter
// of the flash player , title to display in the page, artist to display to the page
// OUTPUT : the string conaining the html code of the page to serve string generateHTML(string urlMEdia, list playList){ string string_ ="<html><style>th{ background-color:#bf00e6;}tr { border-style:solid; border-width:1px; background-color:#b0e0e6;}.artist { font-size:110%; }.title { font-style: italic; color:red; }</style><body><table><tr><th/><th>Title</th><th>Artist</th></tr>"; integer n = llGetListLength(playList); integer i = 0; while ( i < n ) { string_ += "<tr><td class='track'>" + generateEmbededObject(llList2String(playList, i)) + "</td>" + "<td class='title'>" + llList2String(playList, i+1) + "</td>" + "<td class='artist'>" + llList2String(playList, i+2) + "</td></tr>" ; i+=3; }string_ += "</table></body></html>";return string_;}string g_url;
// INPUT url : the url of the media of prim
// OUTPUT : nothing . creates or update the media of prim
show(string url){ integer error_code ; if ( g_url == "" ) error_code = llSetLinkMedia( LINK_THIS, 0, // Side to display the media on. [PRIM_MEDIA_AUTO_PLAY,TRUE, // Show this page immediately PRIM_MEDIA_CURRENT_URL,url, // The url currently showing PRIM_MEDIA_HOME_URL,url, // The url if they hit 'home' PRIM_MEDIA_HEIGHT_PIXELS,512, // Height/width of media texture will be PRIM_MEDIA_WIDTH_PIXELS,512]); // rounded up to nearest power of 2. else if ( g_url != url ) error_code = llSetLinkMedia( LINK_THIS, 0, [ PRIM_MEDIA_CURRENT_URL,url , PRIM_MEDIA_HOME_URL,url ]); if ( error_code != 0 ) { llOwnerSay("ERROR SET MEDIA " + (string) error_code ); } else { llOwnerSay( "MEDIA HOME URL AND CURRENT URL CHANGED " + url); g_url = url; } } default{ state_entry() { g_url = ""; llRequestURL(); } on_rez(integer n) { g_url = ""; llRequestURL(); } http_request(key id, string method, string body) { if (method == URL_REQUEST_GRANTED) { llOwnerSay("URL GRANTED"); show(body + "/"); } else if (method == URL_REQUEST_DENIED) { llOwnerSay( "URL DENIED " + body); } else if (method == "GET") { llSetContentType(id,CONTENT_TYPE_HTML); llHTTPResponse(id,200, generateHTML( g_url, g_playlist) ); } } changed( integer c ) { if ( c & CHANGED_REGION ) {// we want that the our HUD continues to play if we change the region,// even if the media of prim is invalid// if the user refereshes it .. it s dead .. llOwnerSay("CHANGED REGION"); } }}

 

 Set up your media options of your viewer correctly ; Turn your medias on , rotate the prim to the right face , and wear it as hud. 

Buid too an another prim to link with your hud to let the user reduce it on the screen or display it

 

 

To have a hud who plays several playlists, it will be better to have the flash player replaced by javascript .

 

Here one instance

 

The site archive.org  tells who must embed an Iframe by the code

<iframe src="url" width='500' height='400' frameborder='0'></iframe>

We define an id to be able to change this iframe dynamically by javascript  . We will change the src element 

So we create by instance 

<iframe id='frameArchive'  width='500' height='400' frameborder='0'></iframe>

 and the javscript will react to an event by 

 document.getElementById('frameArchive').src=url;

 

 

// our list of playlists .// in fact, the links are the links of the main page .// In this site (archive.org , the documentaion of the site // tells that http://archive.org/details/xxxxxxx// has a generated page http://archive.org/embed/xxxxxxx// that we can set inside an iframe// We will replace the URLs in the javascriptlist g_urls =["http://archive.org/details/1920s-billyMurry-101-110","http://archive.org/details/ShostakovichSymphonyNo.5","http://archive.org/details/SibeliusSymphonyNo.4","http://archive.org/details/1920s-gusArnheimHisAmbassadorHotelOrchestra-41-44","http://archive.org/details/JohnMcCormack];string LSLList2JSArray(list l){    return "['" + llDumpList2String(l,"','") +"']" ;}string generateHTML(string urlMEdia ){    string string_ ="<html><head><script>URLS ="+ LSLList2JSArray(g_urls)+";index = 0;function firstPlaylist(){   url = URLS[0].replace('details', 'embed');   url += '?playlist=1&autoplay=1';   document.getElementById('frameArchive').src=url;}function updatePlaylist(delta){    index+=delta;    if ( index >= URLS.length )        index = 0;    if ( index < 0 )        index =  URLS.length;    url = URLS[index].replace('details', 'embed');    url += '?playlist=1&autoplay=1';    document.getElementById('frameArchive').src=url;}</script></head><body width=512 onLoad='firstPlaylist()'><p>Click on the next button to change playlist</p><p> <input type=button onClick='updatePlaylist(-1)' value='Previous' />  <input type=button onClick='updatePlaylist(1)' value='Next' />  </p><p><iframe id='frameArchive'  width='500' height='400' frameborder='0'></iframe></p></body></html>";return string_;}string g_url;show(string url){    integer error_code ;    if ( g_url == "" )       error_code = llSetLinkMedia( LINK_THIS, 0,                  // Side to display the media on.            [PRIM_MEDIA_AUTO_PLAY,TRUE,      // Show this page immediately             PRIM_MEDIA_CURRENT_URL,url,    // The url currently showing             PRIM_MEDIA_HOME_URL,url,       // The url if they hit 'home'             PRIM_MEDIA_HEIGHT_PIXELS,512,   // Height/width of media texture will be             PRIM_MEDIA_WIDTH_PIXELS,512]);  //   rounded up to nearest power of 2.    else if ( g_url !=  url )       error_code = llSetLinkMedia( LINK_THIS, 0,               [             PRIM_MEDIA_CURRENT_URL,url ,             PRIM_MEDIA_HOME_URL,url             ]);      if ( error_code != 0 )    {        llOwnerSay("ERROR SET MEDIA " + (string) error_code );    }    else    {        llOwnerSay( "MEDIA HOME URL AND CURRENT URL CHANGED " + url);        g_url = url;    }    }  default{    state_entry()    {        g_url = "";        llRequestURL();    }    on_rez(integer n)    {        g_url = "";         llRequestURL();    }    http_request(key id, string method, string body)    {        if (method == URL_REQUEST_GRANTED)        {            llOwnerSay("URL GRANTED");            show(body + "/");        }        else if (method == URL_REQUEST_DENIED)        {            llOwnerSay( "URL DENIED " + body);        }               else if (method == "GET")        {            llSetContentType(id,CONTENT_TYPE_HTML);            llHTTPResponse(id,200, generateHTML( g_url )  );        }    }    changed( integer c )    {            if ( c & CHANGED_REGION )            {                llOwnerSay("CHANGED REGION");             }    }}

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4271 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...