gpt4 book ai didi

javascript - iPhone : Fast Forward & Rewind using HTML5

转载 作者:可可西里 更新时间:2023-11-01 13:40:35 25 4
gpt4 key购买 nike

我不知道如何在 iPhone 上使用 HTML5 为音频播放器执行简单的快进和快退。所有 Apple 文档均表示应为此使用 playbackRate。我已经观看了 WWDC 2009 和 2010 session ,并下载了我能找到的所有示例源代码,但我仍然无法弄清楚。这只适用于视频吗?那么你如何做倒带和快进按钮呢?这是一个小测试示例:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd>">
<html>
<head>
<title>Audio Player</title>
<base href=".">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.6, user-scalable=false”">
<meta name="apple-mobile-web-app-capable" content="YES">
<link rel="apple-touch-icon" href="Images/WebClipIcon.png">

<script type="text/javascript">

function pauseButton() {
var myButton = document.getElementById("audiobutton");
myButton.value = "||";
myButton.style.opacity=".2";
}

function playButton() {
var myButton = document.getElementById("audiobutton");
myButton.value = ">";
myButton.style.opacity=".5";
}

function playPause() {
var audioElement = document.getElementsByTagName('audio')[0];
if (audioElement.paused) {
audioElement.play();
pauseButton();
}else{
audioElement.pause();
playButton();
}
}

var updateProgress = function (e) {
var percentDone = e.target.currentTime / e.target.duration;
}

function myAddListener() {

var audioElement = document.getElementsByTagName('audio')[0];
audioElement.playbackRate = 1.0;
audioElement.addEventListener('progress', function(evt) { updateProgress(evt); }, false);
audioElement.addEventListener('timeupdate', function(evt) { updateProgress(evt); }, false);
audioElement.addEventListener('durationchange', function(evt) { updateProgress(evt); }, false);
}


function rewind() {
var audioElement = document.getElementsByTagName('audio')[0];
audioElement.playbackRate = -3.0;
}

function fastforward() {
var audioElement = document.getElementsByTagName('audio')[0];
audioElement.playbackRate = 3.0;
}

</script>
</head>
<body onload="myAddListener()">
<p>Audio Test<p/>
<audio id="myAudio" src="http://fotf.cdnetworks.net/fotf/mp3/fof_daily_broadcast/ffd_2010/2_april_may_june/ffd_20100607.mp3>" controls></audio><br/>
<input id="audiobutton" type=button onclick="playPause()" value="&gt;">
<input id="rewindbutton" type=button onclick="rewind()" value="&lt;&lt;">
<input id="forwardbutton" type=button onclick="fastforward()" value="&gt;&gt;">
</div>
</body>
</html>

最佳答案

它似乎对我有用。

我必须在您的示例中调整三件事:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd>">
...
<p>Audio Test<p/>
...
<audio id="myAudio" src="http://fotf.cdnetworks.net/fotf/mp3/fof_daily_broadcast/ffd_2010/2_april_may_june/ffd_20100607.mp3>" controls></audio><br/>

更改为:

<!DOCTYPE html>
...
<p>Audio Test</p>
...
<audio id="myAudio" src="http://fotf.cdnetworks.net/fotf/mp3/fof_daily_broadcast/ffd_2010/2_april_may_june/ffd_20100607.mp3" controls></audio><br/>

详情

  1. 更改您的 doctype 以考虑使用 HTML5 元素
  2. 结束 P 标签中的拼写错误
  3. src 属性中的拼写错误

如果这对您不起作用,请告诉我。

关于javascript - iPhone : Fast Forward & Rewind using HTML5 <audio> & playbackRate doesn't work?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3242436/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com