Guest User

dan

a guest
May 19th, 2009
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. Copyright (c) 2005, Fabricio Zuardi
  4.  
  5. All rights reserved.
  6.  
  7.  
  8.  
  9. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  10.  
  11.  
  12.  
  13.     * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  14.  
  15.     * 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.
  16.  
  17.     * 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.
  18.  
  19.  
  20.  
  21. 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.
  22.  
  23. */
  24.  
  25.  
  26.  
  27. //repeat_playlist = true;
  28.  
  29. //playlist_size = 3;
  30.  
  31. //player_title = "customizeable title test"
  32.  
  33. //song_url = "http://downloads.betterpropaganda.com/music/Imperial_Teen-Ivanka_128.mp3";
  34.  
  35. //song_title = "Imperial Teen - Ivanka";
  36.  
  37. //autoload=true
  38.  
  39. //playlist_url = "testplaylist02.xspf"
  40.  
  41. //info_button_text = "Buy Album"
  42.  
  43. //playlist_url = "http://hideout.com.br/shows/radio-test.xspf";
  44.  
  45. //playlist_url = "http://cchits.ning.com/recent/xspf/?xn_auth=no";
  46.  
  47. //radio_mode = true;
  48.  
  49.  
  50.  
  51.  
  52.  
  53. /* import ExternalInterface package */
  54.  
  55.  
  56.  
  57. import flash.external.ExternalInterface;
  58.  
  59.    
  60.  
  61. stop();
  62.  
  63. //constants
  64.  
  65. DEFAULT_PLAYLIST_URL = "http://webjay.org/by/hideout/allshows.xspf";
  66.  
  67. DEFAULT_WELCOME_MSG = "Welcome to Set.r";
  68.  
  69. LOADING_PLAYLIST_MSG = "Loading Playlist...";
  70.  
  71. DEFAULT_LOADED_PLAYLIST_MSG = "- click to start"
  72.  
  73. DEFAULT_INFOBUTTON_TXT = "Track Info"
  74.  
  75. //default playlist if none is passed through query string
  76.  
  77. if(!playlist_url){
  78.  
  79.     if(!song_url){
  80.  
  81.         playlist_url = DEFAULT_PLAYLIST_URL;
  82.  
  83.     }else{
  84.  
  85.         single_music_playlist = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><playlist version=\"1\" xmlns = \"http://xspf.org/ns/0/\"><trackList>";
  86.  
  87.         single_music_playlist += "<track><location>"+song_url+"</location><annotation>"+song_title+"</annotation></track>"
  88.  
  89.         single_music_playlist += "</trackList></playlist>"
  90.  
  91.     }
  92.  
  93. }
  94.  
  95. //info button
  96.  
  97. info_mc._visible=false;
  98.  
  99. if(!info_button_text){
  100.  
  101.     info_button_text = DEFAULT_INFOBUTTON_TXT;
  102.  
  103. }
  104.  
  105.  
  106.  
  107. //variables initialization
  108.  
  109. playlist_array = [];
  110.  
  111. track_index = 0;
  112.  
  113. volume_level = 100;
  114.  
  115. pause_position = 0;
  116.  
  117.  
  118.  
  119. playlist_xml = new XML();
  120.  
  121. playlist_xml.ignoreWhite = true;
  122.  
  123. playlist_xml.onLoad = playlistLoaded;
  124.  
  125. mysound = new Sound(this);
  126.  
  127. playlist_listener = new Object();
  128.  
  129. playlist_list.addEventListener("change", playlist_listener)
  130.  
  131. //play_btn.onPress = playTrack;
  132.  
  133. //functions
  134.  
  135. //xml parser
  136.  
  137. function playlistLoaded (success){
  138.  
  139.     if(success){
  140.  
  141.         var root_node = this.firstChild;
  142.  
  143.         for(var node = root_node.firstChild; node != null; node = node.nextSibling){
  144.  
  145.             if(node.nodeName == "title"){
  146.  
  147.                 playlist_title = node.firstChild.nodeValue;
  148.  
  149.             }
  150.  
  151.             if(node.nodeName == "trackList"){
  152.  
  153.                 //tracks
  154.  
  155.                 var tracks_array = [];
  156.  
  157.                 for(var track_node = node.firstChild; track_node != null; track_node = track_node.nextSibling){
  158.  
  159.                     var track_obj = new Object()
  160.  
  161.                     //track attributes
  162.  
  163.                     for(var track_child = track_node.firstChild; track_child != null; track_child = track_child.nextSibling){
  164.  
  165.                         if(track_child.nodeName=="location"){
  166.  
  167.                             track_obj.location = track_child.firstChild.nodeValue
  168.  
  169.                         }
  170.  
  171.                         if(track_child.nodeName=="image"){
  172.  
  173.                             track_obj.image = track_child.firstChild.nodeValue
  174.  
  175.                         }
  176.  
  177.                         if(track_child.nodeName=="title"){
  178.  
  179.                             track_obj.title = track_child.firstChild.nodeValue
  180.  
  181.                         }
  182.  
  183.                         if(track_child.nodeName=="creator"){
  184.  
  185.                             track_obj.creator = track_child.firstChild.nodeValue
  186.  
  187.                         }
  188.  
  189.                         if(track_child.nodeName=="annotation"){
  190.  
  191.                             track_obj.annotation = track_child.firstChild.nodeValue
  192.  
  193.                         }
  194.  
  195.                         if(track_child.nodeName=="info"){
  196.  
  197.                             track_obj.info = track_child.firstChild.nodeValue
  198.  
  199.                         }
  200.  
  201.                     }
  202.  
  203.                     track_obj.label = (tracks_array.length+1) +". ";
  204.  
  205.                     if(track_obj.title) {
  206.  
  207.                         if(track_obj.creator) {
  208.  
  209.                             track_obj.label += track_obj.creator+' - ';
  210.  
  211.                         }
  212.  
  213.                         track_obj.label += track_obj.title;
  214.  
  215.                     } else {
  216.  
  217.                         track_obj.label += track_obj.annotation;
  218.  
  219.                     }
  220.  
  221.                     tracks_array.push(track_obj)
  222.  
  223.                 }
  224.  
  225.             }
  226.  
  227.         }
  228.  
  229.         playlist_array = tracks_array;
  230.  
  231.         if(!playlist_size) playlist_size = playlist_array.length;
  232.  
  233.         if(autoplay){
  234.  
  235.             loadTrack()
  236.  
  237.         }else{
  238.  
  239.             start_btn_mc.start_btn.onPress = loadTrack;
  240.  
  241.             track_display_mc.display_txt.text = playlist_title+" "+DEFAULT_LOADED_PLAYLIST_MSG;
  242.  
  243.             if(track_display_mc.display_txt._width>track_display_mc.mask_mc._width){
  244.  
  245.                 track_display_mc.onEnterFrame = scrollTitle;
  246.  
  247.             }else{
  248.  
  249.                 track_display_mc.onEnterFrame = null;
  250.  
  251.                 track_display_mc.display_txt._x = 0;
  252.  
  253.             }
  254.  
  255.         }
  256.  
  257.     }else{
  258.  
  259.         annotation_txt.text = "Error opening "+playlist_url;
  260.  
  261.     }
  262.  
  263.  
  264.  
  265. }
  266.  
  267.  
  268.  
  269. playlist_listener.change = function(eventObject){
  270.  
  271.   annotation_txt.text = playlist_list.selectedItem.annotation;
  272.  
  273.   location_txt.text = playlist_list.selectedItem.location;
  274.  
  275. }
  276.  
  277.  
  278.  
  279. function loadTrack(){
  280.  
  281.  
  282.  
  283.     //Radio Mode feature by nosferathoo, more info in: https://sourceforge.net/tracker/index.php?func=detail&aid=1341940&group_id=128363&atid=711474
  284.  
  285.     if (radio_mode && track_index==playlist_size-1) {
  286.  
  287.         playlist_url=playlist_array[track_index].location;
  288.  
  289.         for (i=0;i<playlist_mc.track_count;++i) {
  290.  
  291.             removeMovieClip(playlist_mc.tracks_mc["track_"+i+"_mc"]);
  292.  
  293.         }
  294.  
  295.         playlist_mc.track_count=0;
  296.  
  297.         playlist_size=0;
  298.  
  299.         track_index=0;
  300.  
  301.         autoload=true;
  302.  
  303.         autoplay=true;
  304.  
  305.         loadPlaylist();
  306.  
  307.         return(0);
  308.  
  309.     }
  310.  
  311.  
  312.  
  313.     start_btn_mc.start_btn._visible = false;
  314.  
  315.     track_display_mc.display_txt.text = playlist_array[track_index].label;
  316.  
  317.     if(track_display_mc.display_txt._width>track_display_mc.mask_mc._width){
  318.  
  319.         track_display_mc.onEnterFrame = scrollTitle;
  320.  
  321.     }else{
  322.  
  323.         track_display_mc.onEnterFrame = null;
  324.  
  325.         track_display_mc.display_txt._x = 0;
  326.  
  327.     }
  328.  
  329.     mysound.loadSound(playlist_array[track_index].location,true);
  330.  
  331.     play_mc.gotoAndStop(2)
  332.  
  333.  
  334.  
  335.     //info button
  336.  
  337.     if(playlist_array[track_index].info!=undefined){
  338.  
  339.         info_mc._visible = true;
  340.  
  341.         info_mc.info_btn.onPress = function(){
  342.  
  343.             getURL(playlist_array[track_index].info,"_blank")
  344.  
  345.         }
  346.  
  347.         info_mc.info_btn.onRollOver = function(){
  348.  
  349.             track_display_mc.display_txt.text = info_button_text;
  350.  
  351.         }
  352.  
  353.         info_mc.info_btn.onRollOut = function(){
  354.  
  355.             track_display_mc.display_txt.text = playlist_array[track_index].label;
  356.  
  357.         }
  358.  
  359.     }else{
  360.  
  361.         info_mc._visible = false;
  362.  
  363.     }
  364.  
  365.     resizeUI();
  366.  
  367.     _root.onEnterFrame=function(){
  368.  
  369.         //HACK doesnt need to set the volume at every enterframe
  370.  
  371.         mysound.setVolume(this.volume_level)
  372.  
  373.         var load_percent = (mysound.getBytesLoaded()/mysound.getBytesTotal())*100
  374.  
  375.         track_display_mc.loader_mc.load_bar_mc._xscale = load_percent;
  376.  
  377.         if(mysound.getBytesLoaded()==mysound.getBytesTotal()){
  378.  
  379.             //_root.onEnterFrame = null;
  380.  
  381.         }
  382.  
  383.     }
  384.  
  385. }
  386.  
  387.  
  388.  
  389. stop_btn.onRelease = stopTrack;
  390.  
  391. play_mc.play_btn.onRelease = playTrack
  392.  
  393. next_btn.onRelease = nextTrack
  394.  
  395. prev_btn.onRelease = prevTrack
  396.  
  397. mysound.onSoundComplete = nextTrack;
  398.  
  399. volume_mc.volume_btn.onPress = volumeChange;
  400.  
  401. volume_mc.volume_btn.onRelease = volume_mc.volume_btn.onReleaseOutside = function(){
  402.  
  403.     this._parent.onEnterFrame = null;
  404.  
  405. }
  406.  
  407.  
  408.  
  409. function volumeChange(){
  410.  
  411.     this._parent.onEnterFrame = function(){
  412.  
  413.         var percent = (this._xmouse/this._width)*100
  414.  
  415.         if(percent>100)percent=100;
  416.  
  417.         if(percent<0)percent=0;
  418.  
  419.         this.volume_bar_mc._xscale = percent
  420.  
  421.         this._parent.volume_level = percent;
  422.  
  423.         mysound.setVolume(percent)
  424.  
  425.     }
  426.  
  427. }
  428.  
  429.  
  430.  
  431. function stopTrack() {
  432.  
  433.     mysound.stop();
  434.  
  435.     play_mc.gotoAndStop(1)
  436.  
  437.     mysound.stop();
  438.  
  439.     mysound.start();
  440.  
  441.     mysound.stop();
  442.  
  443.     _root.pause_position = 0;
  444.  
  445.  
  446.  
  447. };
  448.  
  449. function playTrack() {
  450.  
  451.     if(play_mc._currentframe==1){ //play
  452.  
  453.         seekTrack(_root.pause_position)
  454.  
  455.         play_mc.gotoAndStop(2)
  456.  
  457.     }else if(play_mc._currentframe==2){
  458.  
  459.         _root.pause_position = mysound.position;
  460.  
  461.         mysound.stop();
  462.  
  463.         play_mc.gotoAndStop(1)
  464.  
  465.     }
  466.  
  467.  
  468.  
  469. };
  470.  
  471.  
  472.  
  473. function seekTrack(p_offset:Number){
  474.  
  475.     mysound.stop()
  476.  
  477.     mysound.start(int((p_offset)/1000),1)
  478.  
  479. }
  480.  
  481. function nextTrack(){
  482.  
  483.     if(track_index<playlist_size-1){
  484.  
  485.         track_index ++;
  486.  
  487.         loadTrack();
  488.  
  489.     }else{
  490.  
  491.         if(repeat_playlist){
  492.  
  493.             last_track_index = track_index;
  494.  
  495.             track_index = 0;
  496.  
  497.             loadTrack()
  498.  
  499.         }
  500.  
  501.     }
  502.  
  503. }
  504.  
  505.  
  506.  
  507. function prevTrack(){
  508.  
  509.     if(track_index>0){
  510.  
  511.         track_index --;
  512.  
  513.         loadTrack();
  514.  
  515.     }
  516.  
  517. }
  518.  
  519.  
  520.  
  521. function scrollTitle(){
  522.  
  523.     track_display_mc.display_txt._x -= 5;
  524.  
  525.     if (track_display_mc.display_txt._x+track_display_mc.display_txt._width<0){
  526.  
  527.         track_display_mc.display_txt._x = track_display_mc.mask_mc._width;
  528.  
  529.     }
  530.  
  531. }
  532.  
  533.  
  534.  
  535. function resizeUI(){
  536.  
  537.     bg_mc._width = Stage.width;
  538.  
  539.     track_display_mc.loader_mc._width = Stage.width - track_display_mc._x - 3;
  540.  
  541.     track_display_mc.mask_mc._width = track_display_mc.loader_mc._width - 26;
  542.  
  543.     if(track_display_mc.display_txt._width>track_display_mc.mask_mc._width){
  544.  
  545.         track_display_mc.onEnterFrame = scrollTitle;
  546.  
  547.     }else{
  548.  
  549.         track_display_mc.onEnterFrame = null;
  550.  
  551.         track_display_mc.display_txt._x = 0;
  552.  
  553.     }
  554.  
  555.     if (info_mc._visible){
  556.  
  557.         info_mc._x = Stage.width - info_mc._width - 4;
  558.  
  559.     }else{
  560.  
  561.         info_mc._x = Stage.width - 4;
  562.  
  563.     }
  564.  
  565.     volume_mc._x = info_mc._x - volume_mc._width - 2;
  566.  
  567.     start_btn_mc._xscale = Stage.width;
  568.  
  569. }
  570.  
  571.  
  572.  
  573. function loadPlaylist(){
  574.  
  575.    
  576.  
  577.     //attempting to make external js call
  578.  
  579.     ExternalInterface.call("alert", "Hello World!1");
  580.  
  581.     //
  582.  
  583.     track_display_mc.display_txt.text = LOADING_PLAYLIST_MSG;
  584.  
  585.     if(track_display_mc.display_txt._width>track_display_mc.mask_mc._width){
  586.  
  587.         track_display_mc.onEnterFrame = scrollTitle;
  588.  
  589.     }else{
  590.  
  591.         track_display_mc.onEnterFrame = null;
  592.  
  593.         track_display_mc.display_txt._x = 0;
  594.  
  595.     }
  596.  
  597.  
  598.  
  599.     //playlist
  600.  
  601.     if(playlist_url){
  602.  
  603.         playlist_xml.load(playlist_url)
  604.  
  605.     }else{
  606.  
  607.     //single track
  608.  
  609.         playlist_xml.parseXML(single_music_playlist)
  610.  
  611.         playlist_xml.onLoad(true);
  612.  
  613.     }
  614.  
  615. }
  616.  
  617.  
  618.  
  619. //first click - load playlist
  620.  
  621. start_btn_mc.start_btn.onPress = function(){
  622.  
  623.     autoplay = true;
  624.  
  625.     loadPlaylist();
  626.  
  627. }
  628.  
  629.  
  630.  
  631. //main
  632.  
  633. Stage.scaleMode = "noScale"
  634.  
  635. Stage.align = "LT";
  636.  
  637. this.onResize = resizeUI;
  638.  
  639. Stage.addListener(this);
  640.  
  641. if(!player_title) player_title = DEFAULT_WELCOME_MSG;
  642.  
  643. track_display_mc.display_txt.autoSize = "left";
  644.  
  645. track_display_mc.display_txt.text = player_title;
  646.  
  647. if(track_display_mc.display_txt._width>track_display_mc.mask_mc._width){
  648.  
  649.     track_display_mc.onEnterFrame = scrollTitle;
  650.  
  651. }else{
  652.  
  653.     track_display_mc.onEnterFrame = null;
  654.  
  655.     track_display_mc.display_txt._x = 0;
  656.  
  657. }
  658.  
  659. //start to play automatically if parameter autoplay is present
  660.  
  661. if(autoplay){
  662.  
  663.     start_btn_mc.start_btn.onPress();
  664.  
  665. } else if (autoload){
  666.  
  667.     loadPlaylist()
  668.  
  669. }
  670.  
  671.  
  672.  
  673. //customized menu
  674.  
  675. var my_cm:ContextMenu = new ContextMenu();
  676.  
  677. my_cm.customItems.push(new ContextMenuItem("Stop", stopTrack));
  678.  
  679. my_cm.customItems.push(new ContextMenuItem("Play!", playTrack));
  680.  
  681. my_cm.customItems.push(new ContextMenuItem("Next", nextTrack));
  682.  
  683. my_cm.customItems.push(new ContextMenuItem("Previous", prevTrack));
  684.  
  685. my_cm.customItems.push(new ContextMenuItem("Download this song", function(){getURL(playlist_array[track_index].location)},true));
  686.  
  687. my_cm.customItems.push(new ContextMenuItem("Add song to Webjay playlist", function(){getURL("http://webjay.org/poster?media="+escape(playlist_array[track_index].location))}));
  688.  
  689. my_cm.customItems.push(new ContextMenuItem("About Hideout", function(){getURL("http://www.hideout.com.br")},true));
  690.  
  691. //my_cm.customItems.push(new ContextMenuItem("Crossfade", function(){}));
  692.  
  693. //my_cm.customItems.push(new ContextMenuItem("Mando Diao - Paralyzed", function(){}));
  694.  
  695. my_cm.hideBuiltInItems();
  696.  
  697. this.menu = my_cm;
  698.  
  699. resizeUI();
Add Comment
Please, Sign In to add comment