2017-04-20 5 views
0

ビデオをキャプチャしたい。その後、ボタンをクリックしてビデオを再生したい。私はiOSとAndroidアプリのコードバで作業しています。 私はcordova-plugin-media-capturecordova-plugin-streaming-mediaプラグインを使っています。iOSでビデオを作成してコードワイヤでキャプチャする

ビデオ作品を提供しています。私は「プレイ動画」ボタンをクリックしていた場合でも、私は、コンソールにエラーが表示されます。

ReferenceError: Can't find variable: playVideo

いただきましたの?ここに私の機能は次のとおりです。

//cordova media caputre plugin 
document.addEventListener("deviceready", init, false); 
function init() { 

    document.querySelector("#takeVideo").addEventListener("touchend", function() { 
     console.log("Take video"); 
     navigator.device.capture.captureVideo(captureSuccess, captureError, {limit: 1}); 
    }, false); 

} 

function captureError(e) { 
    console.log("capture error: "+JSON.stringify(e)); 
} 

// capture callback 
var captureSuccess = function(mediaFiles) { 
    var i, path, len; 
    for (i = 0, len = mediaFiles.length; i < len; i += 1) { 
     path = mediaFiles[i].fullPath; 
     console.log(mediaFiles[i].fullPath); 

      function playVideo(videoUrl) { 
       // Play a video with callbacks 
       var options = { 
       mustWatch: true, 
       successCallback: function() { 
        console.log("Video was closed without error."); 
       }, 
       errorCallback: function(errMsg) { 
        console.log("Error! " + errMsg); 
       } 
       }; 
       window.plugins.streamingMedia.playVideo(path, options); 

      } 

    } 
}; 

マイボタン(HTML)

<button id="takeVideo">Take Video</button> 

<input type="url" size="60" value="" id="vidUrl"/><br/> 
<button type="button" onclick="playVideo(document.getElementById('vidUrl').value);">Play Video</button> 
+0

あなた自身の関数playVideoの名前を変更しようとしましたか?名前の衝突があるようです。そしておそらく、これはちょうど、あなたが関数の中で関数を宣言してからあなたのHTMLから呼び出すことができないからです。 – Kris

答えて

0

編集

ここで動作するようにコードを調整することで私の試みです:

JavaScriptを。

document.addEventListener("deviceready", init, false); 

function init() { 

    document.getElementById("takeVideo").addEventListener("touchend", function() { 

     console.log("Take video"); 

     navigator.device.capture.captureVideo(captureSuccess, captureError, { 
      limit: 1 
     }); 

    }, false); 

    document.getElementById("playButton").addEventListener("touchend", function() { 

     playVideo(document.getElementById('vidUrl').innerHTML); 

    }); 

} 

function captureError(e) { 

    console.log("capture error: " + JSON.stringify(e)); 
} 


function captureSucess(mediaFile) { 

    //No need for a loop as we have limited the user to take 1 video 
    var path = mediaFile.fullPath; 
    var vidUrlElement = document.getElementById('vidUrl'); 
    vidUrlElement.innerHTML = path; 


} 

function playVideo(videoUrl) { 
    // Play a video with callbacks 
    var options = { 
     mustWatch: true, 
     successCallback: function() { 
      console.log("Video was closed without error."); 
     }, 
     errorCallback: function(errMsg) { 
      console.log("Error! " + errMsg); 
     } 
    }; 
    window.plugins.streamingMedia.playVideo(videoUrl, options); 

} 

HTML;

<button id="takeVideo">Take Video</button> 
<br/> 
<div id="vidUrl"></div> 
<br/> 
<button id="playButton">Play Video</button> 

オリジナル

あなたはforループの外でplayVideo()関数を移動しようとしたことがありますか?

関連する問題