2017-03-10 65 views
1

我試圖在裝有Electron的窗口中播放視頻(mp4)。 奇怪的是:它只用一個視頻就可以正常工作,其他視頻則顯示黑屏。所有視頻的唯一區別是它們的寬度和高度(這是否重要?)。另外,在瀏覽器窗口中,所有視頻都可以播放。電子視頻標籤

下面是在電子加載Windows代碼:

let mainWindow; 
let playerWindow; 


app.on('window-all-closed', function() { 
    if (process.platform != 'darwin') { 
    app.quit(); 
    } 
}); 

app.on('ready', function() { 
    mainWindow = new BrowserWindow({ 
    title: 'MasterGameApp', 
    x: 910, 
    y: 500, 
    width: 800, 
    height: 460, 
    show: true, 
    resizable: false, 
    transparent: false 
}); 

playerWindow = new BrowserWindow({ 
    title: 'playerView', 
    x: 2250, 
    y: 50, 
    width: 1005, 
    height: 540, 
    show: true, 
    transparent: false, 
    fullscreen : true 
}); 

mainWindow.loadURL('http://localhost:8889'); 
mainWindow.setMenuBarVisibility(false); 
mainWindow.setAutoHideMenuBar(true); 
playerWindow.loadUrl('http://localhost:8889/playerView'); 
playerWindow.setMenuBarVisibility(false); 
playerWindow.setAutoHideMenuBar(true); 

mainWindow.on('closed', function() { 
    playerWindow.close(); 
    playerWindow = null; 
    mainWindow = null; 
}); 
}); 

的視頻URL只是給視頻標籤的JS腳本中像這樣$('#someDiv').append('<video id=\'backgroundvid\' autoplay><source src=\''+ content +'\' type=\'video/mp4\'></video>');

我不明白爲什麼瀏覽器可以播放每個視頻,但電子窗口不能...提前致謝

回答

0

嗯。我剛剛看到視頻標記的URL屬性的開頭不包含引號。 你有什麼:

$('#someDiv').append('<video id=\'backgroundvid\' autoplay><source src=\''+ content +'\' type=\'video/mp4\'></video>'); 

你應該有什麼:

$('#someDiv').append('<video id=\'backgroundvid\' autoplay><source src=&quot;\''+ content +'\' type=\'video/mp4\'&quot;></video>'); 

您是否嘗試過改變嗎? 保持點亮;繼續做電子。我非常喜歡它,並且可以看到其未來桌面應用程序的潛力。

另外,我不確定你的CORS設置是什麼或者什麼,但是如果它試圖在本地加載視頻,它可能不會讓你。

+0

謝謝你的回答,但這不是問題,逗號沒問題(只是做了一些測試),這段代碼對於一個視頻(以及瀏覽器中的所有視頻)效果很好,但顯示黑屏與其他視頻(在電子窗口)。 我同意,Electron很酷,也很容易開始 – LongDuZboub

+0

好的,所以我只是轉換文件適當的高度和寬度,並做了這項工作...... – LongDuZboub

+0

@LongDuZboub如果修復它,回答,然後將其標記爲正確? (如果你已經弄清楚爲什麼有高度/寬度限制,那麼也可以在你的答案中輸入:) –