0

我正在尝试在 s JS 幻灯片放映期间播放 mp3。当幻灯片开始播放时,我无法操作要播放的音频标签。

我尝试了一些 JS 和 HTML 标准音频标签,但在幻灯片开始时难以控制音乐播放。

欢迎任何想法(ps 我的 JS 非常基础)!

下面的代码(包括 eivers88 脚本):添加音频脚本时幻灯片无法加载..

<script type="text/javascript" 
src="http://slideshow.triptracker.net/slide.js"></script>
<script type="text/javascript">
<!-- 

//3rd attempt to play audio with slideshow for stackoverflow
var audioType='.mp3';
var audioPlayer = document.createElement('audio');

audioPlayer.setAttribute('src', 'images/Music/Oceans.mp3');
$('body').append(audioPlayer);
audioPlayer.load();
audioPlayer.play();

var viewer = new PhotoViewer();
viewer.enablePhotoFading()
viewer.enableAutoPlay();
viewer.disableToolbarAnimator();
viewer.randomize();
viewer.setOnClickEvent(viewer.permalink);


 viewer.add('images/Gallery/image1.jpg');`enter code here`

 //images enetered as arguments here viewer.add('images/Gallery/image1.jpg');...
4

1 回答 1

1

您是否尝试过一些简单的事情,例如:

var audioType = '.mp3';
var audioPlayer = document.createElement('audio');

if(!!audioPlayer.canPlayType('audio/ogg') === true){
    audioType = '.ogg' //For firefox and others who do not support .mp3
}

audioPlayer.setAttribute('src', 'path/to/song' + audioType);
$('body').append(audioPlayer);
audioPlayer.load();
audioPlayer.play(); //put this where your slide show starts
于 2013-03-15T16:43:20.777 回答