3

HTML5 を使用するオーディオ プレーヤーの iPhone で単純な早送りと巻き戻しを行う方法がわかりません。Apple のすべてのドキュメントには、このために playbackRate を使用する必要があると記載されています。これに関する WWDC 2009 および 2010 セッションを見て、見つけたすべてのサンプル ソース コードをダウンロードしましたが、まだこれを理解できません。これは動画専用ですか?では、巻き戻しと早送りのボタンはどのようにしますか? 小さなテスト例を次に示します。

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

1 に答える 1

2

それは私のために働くようです。

あなたの例で私が微調整しなければならなかった3つのこと:

<!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. doctypeHTML5要素の使用を考慮してアカウントを変更する
  2. 終了Pタグのタイプミス
  3. src属性のタイプミス

これでうまくいかない場合はお知らせください。

于 2011-06-28T02:49:45.783 に答える