原文地址: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

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

Javascript

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

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

Example 2: several synchronized players

View demo

Javascript

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

  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. $(document).ready(function() {
  17. $('.audio').each(function(){
  18. audio_file = $(this).attr('href');
  19. $(this).flash(
  20. {
  21. swf: 'flash/audioplayer.swf',
  22. flashvars:
  23. {
  24. playerID: "'" + audio_file + "'",
  25. soundFile: audio_file
  26. }
  27. }
  28. );
  29. });
  30. });

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

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

Javascript

  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. $(document).ready(function() {
  17. $('.audio').each(function() {
  18. audio_file = $(this).attr('href');
  19. audio_title = $(this).text();
  20. audio_id = $(this).attr('id');
  21. div = $('<div class="audio_flash" id="' + audio_id + '"></div>');
  22. $(this).after(div);
  23. $(this).after(audio_title);
  24. $(this).remove();
  25. div.flash(
  26. {
  27. swf: 'flash/audioplayer.swf',
  28. flashvars:
  29. {
  30. soundFile: audio_file,
  31. playerID: "'" + audio_id + "'",
  32. quality: 'high',
  33. lefticon: '0xFFFFFF',
  34. righticon: '0xFFFFFF',
  35. leftbg: '0x357CCE',
  36. rightbg: '0x32BD63',
  37. rightbghover: '0x2C9D54',
  38. wmode: 'transparent'
  39. },
  40. height: 50
  41. }
  42. );
  43. });
  44. });

<!-- 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-] -->

 

Wordpress 音频播放器 Wordpress audio player with jQuery audioplayer.swf的更多相关文章

  1. 【jquery】一款不错的音频播放器——Amazing Audio Player

    前段时间分享了一款视频播放器,点击这里.今天介绍一款不错的音频播放器——Amazing Audio Player. 介绍: Amazing Audio Player 是一个使用很方便的 Windows ...

  2. 基于canvas和Web Audio的音频播放器

    wavesurfer.js是一款基于HTML5 canvas和Web Audio的音频播放器插件.通过wavesurfer.js你能够使用它来制作各种HTML5音频播放器,它能够在各种支持 Web A ...

  3. 最简单的基于FFMPEG+SDL的音频播放器 ver2 (采用SDL2.0)

    ===================================================== 最简单的基于FFmpeg的音频播放器系列文章列表: <最简单的基于FFMPEG+SDL ...

  4. 最简单的基于FFMPEG+SDL的音频播放器 ver2 (採用SDL2.0)

    ===================================================== 最简单的基于FFmpeg的音频播放器系列文章列表: <最简单的基于FFMPEG+SDL ...

  5. HTML5 音频播放器-Javascript代码(短小精悍)

    直接上干货咯! //HTML5 音频播放器 lzpong 2015/01/19 var wavPlayer = function () { if(window.parent.wavPlayer) re ...

  6. IOS开发之简单音频播放器

    今天第一次接触IOS开发的UI部分,之前学OC的时候一直在模拟的使用Target-Action回调模式,今天算是真正的用了一次.为了熟悉一下基本控件的使用方法,和UI部分的回调,下面开发了一个特别简易 ...

  7. 与众不同 windows phone (14) - Media(媒体)之音频播放器, 视频播放器, 与 Windows Phone 的音乐和视频中心集成

    原文:与众不同 windows phone (14) - Media(媒体)之音频播放器, 视频播放器, 与 Windows Phone 的音乐和视频中心集成 [索引页][源码下载] 与众不同 win ...

  8. Unity3D音频播放器 动态装载组件

    大多数在线Unity有关如何只教程Unity在播放音乐.之后如何通过拖动它们无法继续添加音频文件 但有时在游戏中的对象要玩几个声音.这时候我们就需要使用代码控制,拖动推教程AudioClip颂值的方法 ...

  9. OCiOS开发:音频播放器 AVAudioPlayer

    简单介绍 AVAudioPlayer音频播放器可以提供简单的音频播放功能.其头文件包括在AVFoudation.framework中. AVAudioPlayer未提供可视化界面,须要通过其提供的播放 ...

随机推荐

  1. QObject就有eventFilter,功能很强(随心所欲的进行处理,比如用来QLineEdit分词)

    相信大家都用过词典吧!因为英语不太好...O(∩_∩)O~,所以经常进行划词翻译! 简述 实现 效果 源码 更多参考 实现 原理:鼠标移至某单词之上,获取鼠标位置,然后在对应位置进行取词,翻译! 基于 ...

  2. C# ToString()和Convert.ToString()的区别

    一.一般用法说明 ToString()是Object的扩展方法,所以都有ToString()方法;而Convert.ToString(param)(其中param参数的数据类型可以是各种基本数据类型, ...

  3. MATLAB三维曲面

    今天终于测试了,发下来第一张试卷中只会做一小题.我蒙了!!! 所以呢,我现在再做一下,总结总结! 作函数 f(x)=2(x1-1)4+2x22 的三维图. 这道题要用到的知识点有函数meshgrid. ...

  4. Candy 解答

    Question There are N children standing in a line. Each child is assigned a rating value. You are giv ...

  5. vector迭代器失效的一种情形

    使用过STL的人都应该知道关于迭代器失效的原理,这里以后vector迭代器失效为例: 第一种:当插入一个元素到vector中,如果插入后容器已满,那么容器将新开辟一块内存区域,然后 将原内存中的数据拷 ...

  6. windows 基于命令行制作vhd虚拟磁盘

    什么是VHD? VHD是Virtual Hard Disk的简称,就是虚拟硬盘,就是能把VHD文件直接虚拟成一个硬盘,在其中能像真实硬盘一样操作,读取.写入.创建分区.格式化.如果你用过虚拟机,就会知 ...

  7. Eclipse配置Maven开发环境

    前言: 现在Eclipse版本越来越高.高版本的Eclipse甚至已经集成了Maven像是SpringSource的哪个版本.用习惯了Eclipse.在开发中还是不想更换掉自己的IDE.如此一来就又了 ...

  8. 实现一次请求加载多个js或者css

    http://tengine.taobao.org/   相当牛x

  9. hdu 4627 水数学题

    最小公倍数最大,也就是尽量让2个数互质,所以把n除以2 从中间向两边找就够了,自己写几组数据就能发现规律. 注意longlong存 #include<cstdio> #include< ...

  10. [裸KMP][HDU1711][Number Sequence]

    题意 找到子串在母串出现的第一个位置 解法 裸的KMP 特别的地方 第一次不看模板自己敲的KMP #include<stdio.h> const int maxn=100000; cons ...