HTML 5音频标记多个文件 [英] HTML 5 Audio Tag Multiple Files

查看:166
本文介绍了HTML 5音频标记多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在一个接一个地播放HTML5音频标签中放置两个文件。我到目前为止的代码是:

 < audio id =ListenLive控制自动播放> 
< source src =advert.mp3type =audio / mpeg>
< source src =stream.mp3type =audio / mpeg>

< / audio>

我现在遇到的问题是只有第一个文件会播放并结束,它是就像没有第二个文件一样。只要第一首歌结束,它什么都不做。



有没有办法让第二首曲目在第一首歌结束时自动播放?我需要它在HTML中,因为它是为一个移动网站,所以一些代码可能无法在某些设备上工作

在javascript中你可以这样做(这只是为了让你开始):

  audio = new Audio(start url) ; 

audio.addEventListener('ended',function(){
audio.src =new url;
audio.pause();
audio.load ();
audio.play();
});

如果你想要的话也可以使用相同的播放器(jquery):

  var audio = $(#player); 


I am trying to have two files in one HTML 5 Audio Tag that play one after the other. The code I have so far is:

<audio id="ListenLive" controls autoplay>
<source src="advert.mp3" type="audio/mpeg">
<source src="stream.mp3" type="audio/mpeg">

</audio>

The issue I am having at the moment is that only the first file will play and end, it is like there is no second file. As soon as the first song ends it does nothing else.

Is there a way to get the second track to play automatically when the first one ends? I need it to be in HTML as it is for a mobile site so some code may not work on some devices

解决方案

In javascript you can do it like this (this is just to get you started):

audio = new Audio("start url");

  audio.addEventListener('ended',function(){
        audio.src = "new url";
        audio.pause();
        audio.load();
        audio.play();
    });

if you want you can also use the same player(jquery):

var audio = $("#player");

这篇关于HTML 5音频标记多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆