Guest User

dan

a guest
May 14th, 2009
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @@HTML
  2.  
  3.   <object id="xspf_player" data="http://localhost/musicneverstopped/player_testing/xspf_player_slim.swf?playlist_url=http://localhost/musicneverstopped/player_testing/playlist.xspf?xn_auth=no?radio_mode=true" type="application/x-shockwave-flash" width="400" height="30" align="middle">
  4.     <param name="movie" value="http://localhost/musicneverstopped/player_testing/xspf_player_slim.swf?playlist_url=http://localhost/musicneverstopped/player_testing/playlist.xspf?xn_auth=no?radio_mode=true"/>
  5.     <param name="allowscriptaccess" value="always"/>
  6.     <param name="bgcolor" value="#e6e6e6"/>
  7. </object>
  8.  
  9.  
  10. @@ ActionScript 2.0
  11. /*
  12.  
  13. Copyright (c) 2005, Fabricio Zuardi
  14.  
  15. All rights reserved.
  16.  
  17.  
  18.  
  19. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  20.  
  21.  
  22.  
  23.     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  24.  
  25.     * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  26.  
  27.     * Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
  28.  
  29.  
  30.  
  31. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32.  
  33. */
  34.  
  35.  
  36.  
  37. //repeat_playlist = true;
  38.  
  39. //playlist_size = 3;
  40.  
  41. //player_title = "customizeable title test"
  42.  
  43. //song_url = "http://downloads.betterpropaganda.com/music/Imperial_Teen-Ivanka_128.mp3";
  44.  
  45. //song_title = "Imperial Teen - Ivanka";
  46.  
  47. //autoload=true
  48.  
  49. //playlist_url = "testplaylist02.xspf"
  50.  
  51. //info_button_text = "Buy Album"
  52.  
  53. //playlist_url = "http://hideout.com.br/shows/radio-test.xspf";
  54.  
  55. //playlist_url = "http://cchits.ning.com/recent/xspf/?xn_auth=no";
  56.  
  57. //radio_mode = true;
  58.  
  59.  
  60.  
  61. //including ThunderBolt logging
  62.  
  63. //import org.osflash.thunderbolt.Logger;
  64.  
  65.  
  66.  
  67. //testing external .js calls
  68.  
  69. /* import ExternalInterface package */
  70.  
  71.  
  72.  
  73. import flash.external.*;
  74.  
  75.  
  76.  
  77. /* Create a movieclip for the alert. Set an arbitrary (but very high) number for the depth
  78.  
  79.  * since we want the alert in front of everything else.
  80.  
  81.  */
  82.  
  83.  
  84.  
  85. //var alert = this.createEmptyMovieClip("alert", 32000);
  86.  
  87. /* Create the alert textfield */
  88.  
  89. /*
  90.  
  91. var output_txt = alert.createTextField("output_txt", 1, 0, 0, 300, 200);
  92.  
  93. output_txt.background = true;
  94.  
  95. output_txt.backgroundColor = 0xEFEFEF;
  96.  
  97. output_txt.selectable = false;
  98.  
  99. output_txt.text = (ExternalInterface.available);
  100.  
  101. */
  102.  
  103. /* Set up drag behaviour */
  104.  
  105. /*
  106.  
  107. alert.onPress = function()
  108.  
  109. {
  110.  
  111.     this.startDrag();
  112.  
  113. }
  114.  
  115. alert.onMouseUp = function()
  116.  
  117. {
  118.  
  119.     stopDrag();
  120.  
  121. }
  122.  
  123. */
  124.  
  125. /* I was using a button to text EI. You don't need to. */
  126.  
  127. /*
  128.  
  129. testEI_btn.onPress = function()
  130.  
  131. {
  132.  
  133.     output_txt.text = (ExternalInterface.available);
  134.  
  135. }*/
  136.  
  137.    
  138.  
  139. var isAvailable:Boolean = ExternalInterface.available;
  140.  
  141.    
  142.  
  143. stop();
  144.  
  145. //constants
  146.  
  147. DEFAULT_PLAYLIST_URL = "http://webjay.org/by/hideout/allshows.xspf";
  148.  
  149. DEFAULT_WELCOME_MSG = (isAvailable);
  150.  
  151. LOADING_PLAYLIST_MSG = "Loading Playlist...";
  152.  
  153. DEFAULT_LOADED_PLAYLIST_MSG = "- click to start"
  154.  
  155. DEFAULT_INFOBUTTON_TXT = "Track Info"
  156.  
  157. //default playlist if none is passed through query string
  158.  
  159. if(!playlist_url){
  160.  
  161.     if(!song_url){
  162.  
  163.         playlist_url = DEFAULT_PLAYLIST_URL;
  164.  
  165.     }else{
  166.  
  167.         single_music_playlist = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><playlist version=\"1\" xmlns = \"http://xspf.org/ns/0/\"><trackList>";
  168.  
  169.         single_music_playlist += "<track><location>"+song_url+"</location><annotation>"+song_title+"</annotation></track>"
  170.  
  171.         single_music_playlist += "</trackList></playlist>"
  172.  
  173.     }
  174.  
  175. }
  176.  
  177. //info button
  178.  
  179. info_mc._visible=false;
  180.  
  181. if(!info_button_text){
  182.  
  183.     info_button_text = DEFAULT_INFOBUTTON_TXT;
  184.  
  185. }
  186.  
  187.  
  188.  
  189. //variables initialization
  190.  
  191. playlist_array = [];
  192.  
  193. track_index = 0;
  194.  
  195. volume_level = 100;
  196.  
  197. pause_position = 0;
  198.  
  199.  
  200.  
  201. playlist_xml = new XML();
  202.  
  203. playlist_xml.ignoreWhite = true;
  204.  
  205. playlist_xml.onLoad = playlistLoaded;
  206.  
  207. mysound = new Sound(this);
  208.  
  209. playlist_listener = new Object();
  210.  
  211. playlist_list.addEventListener("change", playlist_listener)
  212.  
  213. //play_btn.onPress = playTrack;
  214.  
  215. //functions
  216.  
  217. //xml parser
  218.  
  219. function playlistLoaded (success){
  220.  
  221.     if(success){
  222.  
  223.         var root_node = this.firstChild;
  224.  
  225.         for(var node = root_node.firstChild; node != null; node = node.nextSibling){
  226.  
  227.             if(node.nodeName == "title"){
  228.  
  229.                 playlist_title = node.firstChild.nodeValue;
  230.  
  231.             }
  232.  
  233.             if(node.nodeName == "trackList"){
  234.  
  235.                 //tracks
  236.  
  237.                 var tracks_array = [];
  238.  
  239.                 for(var track_node = node.firstChild; track_node != null; track_node = track_node.nextSibling){
  240.  
  241.                     var track_obj = new Object()
  242.  
  243.                     //track attributes
  244.  
  245.                     for(var track_child = track_node.firstChild; track_child != null; track_child = track_child.nextSibling){
  246.  
  247.                         if(track_child.nodeName=="location"){
  248.  
  249.                             track_obj.location = track_child.firstChild.nodeValue
  250.  
  251.                         }
  252.  
  253.                         if(track_child.nodeName=="image"){
  254.  
  255.                             track_obj.image = track_child.firstChild.nodeValue
  256.  
  257.                         }
  258.  
  259.                         if(track_child.nodeName=="title"){
  260.  
  261.                             track_obj.title = track_child.firstChild.nodeValue
  262.  
  263.                         }
  264.  
  265.                         if(track_child.nodeName=="creator"){
  266.  
  267.                             track_obj.creator = track_child.firstChild.nodeValue
  268.  
  269.                         }
  270.  
  271.                         if(track_child.nodeName=="annotation"){
  272.  
  273.                             track_obj.annotation = track_child.firstChild.nodeValue
  274.  
  275.                         }
  276.  
  277.                         if(track_child.nodeName=="info"){
  278.  
  279.                             track_obj.info = track_child.firstChild.nodeValue
  280.  
  281.                         }
  282.  
  283.                     }
  284.  
  285.                     track_obj.label = (tracks_array.length+1) +". ";
  286.  
  287.                     if(track_obj.title) {
  288.  
  289.                         if(track_obj.creator) {
  290.  
  291.                             track_obj.label += track_obj.creator+' - ';
  292.  
  293.                         }
  294.  
  295.                         track_obj.label += track_obj.title;
  296.  
  297.                     } else {
  298.  
  299.                         track_obj.label += track_obj.annotation;
  300.  
  301.                     }
  302.  
  303.                     tracks_array.push(track_obj)
  304.  
  305.                 }
  306.  
  307.             }
  308.  
  309.         }
  310.  
  311.         playlist_array = tracks_array;
  312.  
  313.         if(!playlist_size) playlist_size = playlist_array.length;
  314.  
  315.         if(autoplay){
  316.  
  317.             loadTrack()
  318.  
  319.         }else{
  320.  
  321.             start_btn_mc.start_btn.onPress = loadTrack;
  322.  
  323.             track_display_mc.display_txt.text = playlist_title+" "+DEFAULT_LOADED_PLAYLIST_MSG;
  324.  
  325.             if(track_display_mc.display_txt._width>track_display_mc.mask_mc._width){
  326.  
  327.                 track_display_mc.onEnterFrame = scrollTitle;
  328.  
  329.             }else{
  330.  
  331.                 track_display_mc.onEnterFrame = null;
  332.  
  333.                 track_display_mc.display_txt._x = 0;
  334.  
  335.             }
  336.  
  337.         }
  338.  
  339.     }else{
  340.  
  341.         annotation_txt.text = "Error opening "+playlist_url;
  342.  
  343.     }
  344.  
  345.  
  346.  
  347. }
  348.  
  349.  
  350.  
  351. playlist_listener.change = function(eventObject){
  352.  
  353.   annotation_txt.text = playlist_list.selectedItem.annotation;
  354.  
  355.   location_txt.text = playlist_list.selectedItem.location;
  356.  
  357. }
  358.  
  359.  
  360.  
  361. function loadTrack(){
  362.  
  363.  
  364.  
  365.     //Radio Mode feature by nosferathoo, more info in: https://sourceforge.net/tracker/index.php?func=detail&aid=1341940&group_id=128363&atid=711474
  366.  
  367.     if (radio_mode && track_index==playlist_size-1) {
  368.  
  369.         playlist_url=playlist_array[track_index].location;
  370.  
  371.         for (i=0;i<playlist_mc.track_count;++i) {
  372.  
  373.             removeMovieClip(playlist_mc.tracks_mc["track_"+i+"_mc"]);
  374.  
  375.         }
  376.  
  377.         playlist_mc.track_count=0;
  378.  
  379.         playlist_size=0;
  380.  
  381.         track_index=0;
  382.  
  383.         autoload=true;
  384.  
  385.         autoplay=true;
  386.  
  387.         loadPlaylist();
  388.  
  389.         return(0);
  390.  
  391.     }
  392.  
  393.  
  394.  
  395.     start_btn_mc.start_btn._visible = false;
  396.  
  397.     track_display_mc.display_txt.text = playlist_array[track_index].label;
  398.  
  399.     if(track_display_mc.display_txt._width>track_display_mc.mask_mc._width){
  400.  
  401.         track_display_mc.onEnterFrame = scrollTitle;
  402.  
  403.     }else{
  404.  
  405.         track_display_mc.onEnterFrame = null;
  406.  
  407.         track_display_mc.display_txt._x = 0;
  408.  
  409.     }
  410.  
  411.     mysound.loadSound(playlist_array[track_index].location,true);
  412.  
  413.     play_mc.gotoAndStop(2)
  414.  
  415.  
  416.  
  417.     //info button
  418.  
  419.     if(playlist_array[track_index].info!=undefined){
  420.  
  421.         info_mc._visible = true;
  422.  
  423.         info_mc.info_btn.onPress = function(){
  424.  
  425.             getURL(playlist_array[track_index].info,"_blank")
  426.  
  427.         }
  428.  
  429.         info_mc.info_btn.onRollOver = function(){
  430.  
  431.             track_display_mc.display_txt.text = info_button_text;
  432.  
  433.         }
  434.  
  435.         info_mc.info_btn.onRollOut = function(){
  436.  
  437.             track_display_mc.display_txt.text = playlist_array[track_index].label;
  438.  
  439.         }
  440.  
  441.     }else{
  442.  
  443.         info_mc._visible = false;
  444.  
  445.     }
  446.  
  447.     resizeUI();
  448.  
  449.     _root.onEnterFrame=function(){
  450.  
  451.         //HACK doesnt need to set the volume at every enterframe
  452.  
  453.         mysound.setVolume(this.volume_level)
  454.  
  455.         var load_percent = (mysound.getBytesLoaded()/mysound.getBytesTotal())*100
  456.  
  457.         track_display_mc.loader_mc.load_bar_mc._xscale = load_percent;
  458.  
  459.         if(mysound.getBytesLoaded()==mysound.getBytesTotal()){
  460.  
  461.             //_root.onEnterFrame = null;
  462.  
  463.         }
  464.  
  465.     }
  466.  
  467. }
  468.  
  469.  
  470.  
  471. stop_btn.onRelease = stopTrack;
  472.  
  473. play_mc.play_btn.onRelease = playTrack
  474.  
  475. next_btn.onRelease = nextTrack
  476.  
  477. prev_btn.onRelease = prevTrack
  478.  
  479. mysound.onSoundComplete = nextTrack;
  480.  
  481. volume_mc.volume_btn.onPress = volumeChange;
  482.  
  483. volume_mc.volume_btn.onRelease = volume_mc.volume_btn.onReleaseOutside = function(){
  484.  
  485.     this._parent.onEnterFrame = null;
  486.  
  487. }
  488.  
  489.  
  490.  
  491. function volumeChange(){
  492.  
  493.     this._parent.onEnterFrame = function(){
  494.  
  495.         var percent = (this._xmouse/this._width)*100
  496.  
  497.         if(percent>100)percent=100;
  498.  
  499.         if(percent<0)percent=0;
  500.  
  501.         this.volume_bar_mc._xscale = percent
  502.  
  503.         this._parent.volume_level = percent;
  504.  
  505.         mysound.setVolume(percent)
  506.  
  507.     }
  508.  
  509. }
  510.  
  511.  
  512.  
  513. function stopTrack() {
  514.  
  515.     mysound.stop();
  516.  
  517.     play_mc.gotoAndStop(1)
  518.  
  519.     mysound.stop();
  520.  
  521.     mysound.start();
  522.  
  523.     mysound.stop();
  524.  
  525.     _root.pause_position = 0;
  526.  
  527.  
  528.  
  529. };
  530.  
  531. function playTrack() {
  532.  
  533.     if(play_mc._currentframe==1){ //play
  534.  
  535.         seekTrack(_root.pause_position)
  536.  
  537.         play_mc.gotoAndStop(2)
  538.  
  539.     }else if(play_mc._currentframe==2){
  540.  
  541.         _root.pause_position = mysound.position;
  542.  
  543.         mysound.stop();
  544.  
  545.         play_mc.gotoAndStop(1)
  546.  
  547.     }
  548.  
  549.  
  550.  
  551. };
  552.  
  553.  
  554.  
  555. function seekTrack(p_offset:Number){
  556.  
  557.     mysound.stop()
  558.  
  559.     mysound.start(int((p_offset)/1000),1)
  560.  
  561. }
  562.  
  563. function nextTrack(){
  564.  
  565.     if(track_index<playlist_size-1){
  566.  
  567.         track_index ++;
  568.  
  569.         loadTrack();
  570.  
  571.     }else{
  572.  
  573.         if(repeat_playlist){
  574.  
  575.             last_track_index = track_index;
  576.  
  577.             track_index = 0;
  578.  
  579.             loadTrack()
  580.  
  581.         }
  582.  
  583.     }
  584.  
  585. }
  586.  
  587.  
  588.  
  589. function prevTrack(){
  590.  
  591.     if(track_index>0){
  592.  
  593.         track_index --;
  594.  
  595.         loadTrack();
  596.  
  597.     }
  598.  
  599. }
  600.  
  601.  
  602.  
  603. function scrollTitle(){
  604.  
  605.     track_display_mc.display_txt._x -= 5;
  606.  
  607.     if (track_display_mc.display_txt._x+track_display_mc.display_txt._width<0){
  608.  
  609.         track_display_mc.display_txt._x = track_display_mc.mask_mc._width;
  610.  
  611.     }
  612.  
  613. }
  614.  
  615.  
  616.  
  617. function resizeUI(){
  618.  
  619.     bg_mc._width = Stage.width;
  620.  
  621.     track_display_mc.loader_mc._width = Stage.width - track_display_mc._x - 3;
  622.  
  623.     track_display_mc.mask_mc._width = track_display_mc.loader_mc._width - 26;
  624.  
  625.     if(track_display_mc.display_txt._width>track_display_mc.mask_mc._width){
  626.  
  627.         track_display_mc.onEnterFrame = scrollTitle;
  628.  
  629.     }else{
  630.  
  631.         track_display_mc.onEnterFrame = null;
  632.  
  633.         track_display_mc.display_txt._x = 0;
  634.  
  635.     }
  636.  
  637.     if (info_mc._visible){
  638.  
  639.         info_mc._x = Stage.width - info_mc._width - 4;
  640.  
  641.     }else{
  642.  
  643.         info_mc._x = Stage.width - 4;
  644.  
  645.     }
  646.  
  647.     volume_mc._x = info_mc._x - volume_mc._width - 2;
  648.  
  649.     start_btn_mc._xscale = Stage.width;
  650.  
  651. }
  652.  
  653.  
  654.  
  655. function loadPlaylist(){
  656.  
  657.     //import ExternalInterface
  658.  
  659.     import flash.external.*;
  660.  
  661.     flash.external.ExternalInterface.call("alert", "Hello World!1");
  662.  
  663.     //attempting to make external js call
  664.  
  665.     flash.external.ExternalInterface.call("createPlaylist","It's my Life!");
  666.  
  667.     //attempt
  668.  
  669.     var output_txt:TextField = new TextField();
  670.  
  671.     addChild(output_txt);
  672.  
  673.     output_txt.text = (String(ExternalInterface.available));
  674.  
  675.     //beefed out version
  676.  
  677.    
  678.  
  679. //end EXTERNALiNTERFACE
  680.  
  681.    
  682.  
  683.     //
  684.  
  685.     track_display_mc.display_txt.text = LOADING_PLAYLIST_MSG;
  686.  
  687.     if(track_display_mc.display_txt._width>track_display_mc.mask_mc._width){
  688.  
  689.         track_display_mc.onEnterFrame = scrollTitle;
  690.  
  691.     }else{
  692.  
  693.         track_display_mc.onEnterFrame = null;
  694.  
  695.         track_display_mc.display_txt._x = 0;
  696.  
  697.     }
  698.  
  699.  
  700.  
  701.     //playlist
  702.  
  703.     if(playlist_url){
  704.  
  705.         playlist_xml.load(playlist_url)
  706.  
  707.     }else{
  708.  
  709.     //single track
  710.  
  711.         playlist_xml.parseXML(single_music_playlist)
  712.  
  713.         playlist_xml.onLoad(true);
  714.  
  715.     }
  716.  
  717. }
  718.  
  719.  
  720.  
  721. //first click - load playlist
  722.  
  723. start_btn_mc.start_btn.onPress = function(){
  724.  
  725.     autoplay = true;
  726.  
  727.     loadPlaylist();
  728.  
  729. }
  730.  
  731.  
  732.  
  733. //main
  734.  
  735. Stage.scaleMode = "noScale"
  736.  
  737. Stage.align = "LT";
  738.  
  739. this.onResize = resizeUI;
  740.  
  741. Stage.addListener(this);
  742.  
  743. if(!player_title) player_title = DEFAULT_WELCOME_MSG;
  744.  
  745. track_display_mc.display_txt.autoSize = "left";
  746.  
  747. track_display_mc.display_txt.text = player_title;
  748.  
  749. if(track_display_mc.display_txt._width>track_display_mc.mask_mc._width){
  750.  
  751.     track_display_mc.onEnterFrame = scrollTitle;
  752.  
  753. }else{
  754.  
  755.     track_display_mc.onEnterFrame = null;
  756.  
  757.     track_display_mc.display_txt._x = 0;
  758.  
  759. }
  760.  
  761. //start to play automatically if parameter autoplay is present
  762.  
  763. if(autoplay){
  764.  
  765.     start_btn_mc.start_btn.onPress();
  766.  
  767. } else if (autoload){
  768.  
  769.     loadPlaylist()
  770.  
  771. }
  772.  
  773.  
  774.  
  775. //customized menu
  776.  
  777. var my_cm:ContextMenu = new ContextMenu();
  778.  
  779. my_cm.customItems.push(new ContextMenuItem("Stop", stopTrack));
  780.  
  781. my_cm.customItems.push(new ContextMenuItem("Play!", playTrack));
  782.  
  783. my_cm.customItems.push(new ContextMenuItem("Next", nextTrack));
  784.  
  785. my_cm.customItems.push(new ContextMenuItem("Previous", prevTrack));
  786.  
  787. my_cm.customItems.push(new ContextMenuItem("Download this song", function(){getURL(playlist_array[track_index].location)},true));
  788.  
  789. my_cm.customItems.push(new ContextMenuItem("Add song to Webjay playlist", function(){getURL("http://webjay.org/poster?media="+escape(playlist_array[track_index].location))}));
  790.  
  791. my_cm.customItems.push(new ContextMenuItem("About Hideout", function(){getURL("http://www.hideout.com.br")},true));
  792.  
  793. //my_cm.customItems.push(new ContextMenuItem("Crossfade", function(){}));
  794.  
  795. //my_cm.customItems.push(new ContextMenuItem("Mando Diao - Paralyzed", function(){}));
  796.  
  797. my_cm.hideBuiltInItems();
  798.  
  799. this.menu = my_cm;
  800.  
  801. resizeUI();
Add Comment
Please, Sign In to add comment