2017-04-20 68 views
0

我想捕捉視頻。之後,我想點擊一個按鈕後播放視頻。我正在與科爾多瓦合作開發iOS和Android應用程序。 我正在使用cordova-plugin-media-capturecordova-plugin-streaming-media插件。在科爾多瓦創建和捕捉iOS視頻

Caputring the video works finde。但如果我點擊「播放視頻」按鈕,我在控制檯中得到一個錯誤:

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> 

原始

您是否嘗試過的外移動的playVideo()函數的循環?