Electron/AngularJS - 从 showOpenDialog 动态加载视频文件

Electron/AngularJS - Dynamically load video file from showOpenDialog

我是菜鸟,对一些事情还是一头雾水。

我在 Electron 中使用 Angular 1.5.8,当在 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 是正确的(如果我以相同的方式在单独的文件中打开此文件路径,它会起作用)。

但是当我按下开始时文件没有开始缓冲。我做错了什么?

我用 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>