Wordpress 音频播放器 Wordpress audio player with jQuery audioplayer.swf

原文地址:http://justcoding.iteye.com/blog/545978

Wordpress audio player with jQuery

How to use Wordpress audio player (standalone version) with jQuery and jQuery SWFObject (progressive enhancement).

<!-- SECTION "Wordpress audio player with jQuery" [1-272] -->

Example 1: basic

View demo

HTML

Java代码   收藏代码
  1. <a class="audio" href="audio/reason.mp3">  
  2.     Audio: An Electronic Reason  
  3. </a>  
 

Javascript

<!-- SECTION "Example 1: basic" [273-705] -->

Java代码   收藏代码
  1. $('.audio').each(function(){  
  2.     audio_file = $(this).attr('href');   
  3.    
  4.     $(this).flash(  
  5.         {  
  6.             swf: 'flash/audioplayer.swf',  
  7.             flashvars:  
  8.             {  
  9.                 soundFile: audio_file  
  10.             }  
  11.         }  
  12.     );  
  13. });  
 

Example 2: several synchronized players

View demo

Javascript

<!-- SECTION "Example 2: several synchronized players" [706-1488] -->

Java代码   收藏代码
  1. // close other audio players  
  2. // called by audio player when click on play button   
  3. function ap_stopAll(player_id)  
  4. {  
  5.     $('.audio').each(function(){  
  6.         if($(this).attr('href') != player_id)  
  7.         {  
  8.             $(this).find('object')[0].SetVariable("closePlayer", 1);  
  9.         }  
  10.         else   
  11.         {  
  12.             $(this).find('object')[0].SetVariable("closePlayer", 0);  
  13.         }  
  14.     });  
  15. }   
  16.    
  17. $(document).ready(function() {  
  18.     $('.audio').each(function(){  
  19.    
  20.         audio_file = $(this).attr('href');   
  21.    
  22.         $(this).flash(  
  23.             {  
  24.                 swf: 'flash/audioplayer.swf',  
  25.                 flashvars:  
  26.                 {  
  27.                     playerID: "'" + audio_file + "'",  
  28.                     soundFile: audio_file  
  29.                 }  
  30.             }  
  31.         );  
  32.     });  
  33. });  
 

Notes

How it works:

  • players are given an id upon initialization
  • when click on play button, player calls  ap_stopAll() with its id as parameter
  • ap_stopAll(): stops all players but the one with this id
  • the id here is the audio file path, but anything else is possible.

<!-- SECTION "Notes" [1489-1786] -->

Example 3: real world

View demo

HTML  

Java代码   收藏代码
  1. <p>  
  2.     <a class="audio" href="audio/reason.mp3" id="reason">  
  3.         Audio: An Electronic Reason  
  4.     </a>                                                       
  5. </p>  
  6.    
  7. <p>  
  8.     <a class="audio" href="audio/sunday.mp3" id="sunday">  
  9.         Audio: By Sunday Afternoon  
  10.     </a>  
  11. </p>  
 

Javascript

 

Java代码   收藏代码
  1. // close other audio players  
  2. // called by audio player when click on play button   
  3. function ap_stopAll(player_id)  
  4. {  
  5.     $('.audio_flash').each(function(){  
  6.         if($(this).attr('id') != player_id)  
  7.         {  
  8.             $(this).find('object')[0].SetVariable("closePlayer", 1);  
  9.         }  
  10.         else   
  11.         {  
  12.             $(this).find('object')[0].SetVariable("closePlayer", 0);  
  13.         }  
  14.     });  
  15. }  
  16.    
  17. $(document).ready(function() {  
  18.    
  19.     $('.audio').each(function() {  
  20.         audio_file = $(this).attr('href');   
  21.         audio_title = $(this).text();  
  22.         audio_id = $(this).attr('id');  
  23.    
  24.         div = $('<div class="audio_flash" id="' + audio_id + '"></div>');         
  25.         $(this).after(div);  
  26.         $(this).after(audio_title);  
  27.         $(this).remove();  
  28.         div.flash(  
  29.             {  
  30.                 swf: 'flash/audioplayer.swf',  
  31.                 flashvars:  
  32.                 {  
  33.                     soundFile: audio_file,  
  34.                     playerID: "'" + audio_id + "'",  
  35.                     quality: 'high',  
  36.                     lefticon: '0xFFFFFF',  
  37.                     righticon: '0xFFFFFF',  
  38.                     leftbg: '0x357CCE',  
  39.                     rightbg: '0x32BD63',  
  40.                     rightbghover: '0x2C9D54',  
  41.                     wmode: 'transparent'  
  42.                 },  
  43.                 height: 50  
  44.             }  
  45.         );  
  46.     });  
  47.    
  48. });  

<!-- SECTION "Example 3: real world" [1787-3238] -->

Notes

  • meaningful HTML: visitors without Javascript get a download link, otherwise it's replaced by plain text and the player

  • the appearance can be customized with  many options (bottom of the page).
  • the default white space before and after the player is reduced by the “height” Flash parameter.
  • use of a custom id (set on the HTML link)

<!-- SECTION "Notes" [3239-3682] -->

Download

<!-- SECTION "Download" [3683-] -->

我提供的文件上传至博客根目录下,然后登陆博客,后台管理-界面与插件-设置模块-添加新模块 选择侧边模块,名字和描述都写Music,至于排序,就看你想放在什么益,自己定就行了,点保存模块, 然后找到你刚新建的模块,点击"编辑HTML ",填如以下代码: <!--音乐播放器开始--> <div xss=removed> [removed] <!-- if (window != top){ AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0, 19,0','width','180','height','30','src','Music/AudioPlayer','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','wmode','opaque','menu','false','movie','Music/ AudioPlayer' ); //end AC code } //--> [removed] <span xss=removed>mp</span></div> 保存即可,关闭后台, 找到博客根目录下面的header.asp文件,在[removed][removed]后面添加上[removed][removed],如果找不到,用搜索,我的是2.7版,在第57行 保存并上传即可, 最后列出音乐插件的文件层次结构 blog根目录/default.htm                               首页框架调用文件,视空间的默认首页文档不 同,自己修改 blog根目录/Music/Scripts/AC_RunActiveContent.js      控制播放的JS blog根目录/Music/AudioPlayer.swf                     播放控制Flash blog根目录/Music/HiddenPlayer.swf                    音乐播放Flash blog根目录/Music/HiddenPlayer.htm                    播放页 blog根目录/Music/mp3_list.xml                        音乐列表問題補充: 如果裝好了不顯示,一般是因爲空間的首頁文檔問題,請自行檢查並修改 blog根目录/default.htm 文件名
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值