`
天梯梦
  • 浏览: 13764622 次
  • 性别: Icon_minigender_2
  • 来自: 洛杉矶
社区版块
存档分类
最新评论

Wordpress 音频播放器 Wordpress audio player with jQuery

阅读更多

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

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

Javascript

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

$('.audio').each(function(){
	audio_file = $(this).attr('href'); 
 
	$(this).flash(
		{
			swf: 'flash/audioplayer.swf',
			flashvars:
			{
				soundFile: audio_file
			}
		}
	);
});
 

Example 2: several synchronized players

View demo

Javascript

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

// close other audio players
// called by audio player when click on play button 
function ap_stopAll(player_id)
{
	$('.audio').each(function(){
		if($(this).attr('href') != player_id)
		{
			$(this).find('object')[0].SetVariable("closePlayer", 1);
		}
		else 
		{
			$(this).find('object')[0].SetVariable("closePlayer", 0);
		}
	});
} 
 
$(document).ready(function() {
	$('.audio').each(function(){
 
		audio_file = $(this).attr('href'); 
 
		$(this).flash(
			{
				swf: 'flash/audioplayer.swf',
				flashvars:
				{
				    playerID: "'" + audio_file + "'",
				    soundFile: audio_file
				}
			}
		);
	});
});
 

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  

<p>
	<a class="audio" href="audio/reason.mp3" id="reason">
		Audio: An Electronic Reason
	</a>                                                     
</p>
 
<p>
	<a class="audio" href="audio/sunday.mp3" id="sunday">
		Audio: By Sunday Afternoon
	</a>
</p>
 

Javascript

 

// close other audio players
// called by audio player when click on play button 
function ap_stopAll(player_id)
{
	$('.audio_flash').each(function(){
		if($(this).attr('id') != player_id)
		{
			$(this).find('object')[0].SetVariable("closePlayer", 1);
		}
		else 
		{
			$(this).find('object')[0].SetVariable("closePlayer", 0);
		}
	});
}
 
$(document).ready(function() {
 
	$('.audio').each(function() {
		audio_file = $(this).attr('href'); 
		audio_title = $(this).text();
		audio_id = $(this).attr('id');
 
		div = $('<div class="audio_flash" id="' + audio_id + '"></div>');		
		$(this).after(div);
		$(this).after(audio_title);
		$(this).remove();
		div.flash(
			{
				swf: 'flash/audioplayer.swf',
				flashvars:
				{
					soundFile: audio_file,
					playerID: "'" + audio_id + "'",
					quality: 'high',
					lefticon: '0xFFFFFF',
					righticon: '0xFFFFFF',
					leftbg: '0x357CCE',
					rightbg: '0x32BD63',
					rightbghover: '0x2C9D54',
					wmode: 'transparent'
				},
				height: 50
			}
		);
	});
 
});

<!-- 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 ++++html5音频播放器

    **WordPress ++++html5音频播放器** 在WordPress中集成HTML5音频播放器是现代网站增强用户体验的一个重要方式,尤其对于音乐分享或者在线电台站点来说,一个功能强大的HTML5音频播放器能够提供无缝的音乐播放体验。...

    Vanilla-JS-Audio-Player:带有ACF中继器的Vanilla JS音频播放器

    【标题】"Vanilla-JS-Audio-Player:带有ACF中继器的Vanilla JS音频播放器"是一个使用纯JavaScript编写的音频播放器项目,它利用了Advanced Custom Fields(ACF)插件的中继器功能。这个项目旨在提供一个轻量级且...

    McPlayer:McPlayer,全功能音频播放器,具有使用HTML5CSSJSAJAX构建的播放列表,Wordpress插件

    McPlayer是一个全功能HTML5 / JS / AJAX音频播放器,带有播放列表和WordPress插件。 描述 McPlayer是使用来自的JS构建的 jQuery的页面过渡不引人注目。 jQueryHTML5音频和视频 带有播放列表和简约视图的Web音频...

    在线电台网页模板

    可能使用HTML5的`audio`标签或者JavaScript库,如JQuery Audio Player或Howler.js。 4. **AJAX与JavaScript**: AJAX(异步JavaScript和XML)用于无刷新更新内容,提升用户体验。在电台模板中,这可能应用于实时更新...

Global site tag (gtag.js) - Google Analytics