2016-11-22 48 views
1

我是一個noob,仍然對某些事情感到困惑。Electron/AngularJS - 從showOpenDialog動態加載視頻文件

我使用的是Angular 1.5.8和Electron,我試圖在main.js中選擇dialog.showOpenDialog文件時啓動視頻加載器。

main.js

click(item, focusedWindow) { 
    dialog.showOpenDialog(
    win, { 
     filters: [{ 
     name: 'Video files', 
     extensions: ['mkv', 'avi', 'mp4'] 
     }], 
     properties: ['openFile'] 
    }, (fileNames) => { 
     if (fileNames === undefined) return; 
     var videoFilePath = fileNames[0]; 
     win.webContents.send('videoFilePath', videoFilePath); 
    } 
); 
} 

videoCtrl.js

const electron = require('electron') 
const ipcRenderer = electron.ipcRenderer 
var app = angular.module('videoModule', []); 

app.controller('videoCtrl', function($scope) { 

    $scope.isVideoOpened = false; 

    ipcRenderer.on('videoFilePath', function(event, arg) { 
    $scope.videoPathFile = arg; 
    $scope.isVideoOpened = true; 
    }); 

}); 

HTML

<div ng-controller="videoCtrl" ng-show="isVideoOpened"> 
    Here {{isVideoOpened}} Here2{{videoPathFile}} 
    <video id="v1" controls tabindex="0" autobuffer> 
    <source type="video/mp4; codecs=&quot;avc1.42E01E, mp4a.40.2&quot;" src="{{videoPathFile}}" /> 
    </video> 
</div> 

當我打開視頻,在isVideoOpened設置爲true和videoPathFile是正確的(如果我打開這個文件路徑在單獨的工作方式相同)。

但是,當我按下開始時文件不會開始緩衝。我究竟做錯了什麼?

回答

0

我用ng-if代替ng-show解決了問題。

但有些細節喜歡它說here

基本上ng-if生成一個子範圍,所以我需要把它放在一個內部標籤,我也需要使用ng-src

<div ng-controller="videoCtrl" > 
    <div ng-if="isVideoOpened"> 
     <video id="v1" controls class="videoInsert"> 
      <source type="video/mp4; codecs=&quot;avc1.42E01E, mp4a.40.2&quot;" ng-src="{{videoPathFile}}" /> 
     </video> 
    </div> 
</div>