0

我能够捕获音频并且我拥有捕获文件的完整路径,但是我无法让它播放最近捕获的文件。

我在 iOS 6.1 上使用 Phongap 2.5 和 Jquery Mobile。

代码:

        <script type="text/javascript" charset="utf-8">
            function captureSuccess(mediaFiles) {
                var i, len;
                var formatSuccess = function (mediaFile) {
                    document.getElementById('capture-data').innerHTML =
                    "Duration: <strong>" + mediaFile.duration + "</strong><br/>";
                };

                for (i = 0, len = mediaFiles.length; i < len; i += 1) {
                    // uploadFile(mediaFiles[i]);
                    document.getElementById('capture-result').innerHTML = "<strong>" + (i+1) + " file(s), Path: " + mediaFiles[i].fullPath + "</strong><br/>";
                    mediaFiles[i].getFormatData(formatSuccess, formatError);
                    readDataUrl = mediaFiles[i].fullPath;
                };

                console.log("captureImageSuccess");
            }


            function captureError(error) {
                var msg = 'An error occurred during capture: ' + error.code;
                navigator.notification.alert(msg, null, 'Uh oh!');
            }

            function captureAudio() {
                // Launch device audio recording application,
                // allowing user to capture up to 2 audio clips
                navigator.device.capture.captureAudio(captureSuccess, captureError, {limit: 2});
            }

            $("#audio-result").click(function() {
                function playAudio(mediaFiles) {
                var play = document.getElementById('audio-result').src =
                mediaFiles[i].fullPath;
            }
                                     });

            </script>
    </head>
    <body>
        <button onclick="captureAudio();">Capture Audio</button> <br>

        <div class="result-block">
            Capture Result: <span id="capture-result"></span><br/>
            <span id="capture-data"></span><br/>
            <button id="audio-result">Play audio</button>
            </div>

    </body>
</html>
4

1 回答 1

0

你可以播放你的媒体如下

var my_media = null;

// here src is the uri of your media
// Create Media object from src
my_media = new Media(src, onSuccess, onError);

// Play audio
my_media.play()

// Pause audio
function pauseAudio() {
    if (my_media) {
        my_media.pause();
    }
}

// Stop audio
function stopAudio() {
    if (my_media) {
        my_media.stop();
    }
}
于 2013-03-05T12:16:14.157 回答