-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvideoplay.js
66 lines (61 loc) · 1.78 KB
/
videoplay.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const { ipcRenderer } = require('electron');
let userName;
ipcRenderer.on('platform-info', (event, { isMac }) => {
if (isMac) {
const styleSheet = document.createElement('style');
styleSheet.textContent = `
.sidebar {
background-color: initial !important;
}
@media (prefers-color-scheme: dark) {
.sidebar {
background-color: initial !important;
}
}
`;
document.head.appendChild(styleSheet);
}
});
function selectFile() {
document.getElementById('file-input').click();
}
function allowDrop(event) {
event.preventDefault(); // 阻止浏览器默认打开文件操作
}
function dropFile(event) {
event.preventDefault(); // 阻止浏览器默认打开文件操作
const files = event.dataTransfer.files;
if (files.length > 0) {
handleFile(files[0]);
}
}
document.getElementById('file-input').addEventListener('change', function(event) {
const files = event.target.files;
if (files.length > 0) {
handleFile(files[0]);
}
});
function handleFile(file) {
if (file.type.startsWith('video/')) {
// 是视频文件,执行打开视频文件的操作
openVideoFile(file);
} else {
alert('请拖放视频文件');
}
}
function openVideoFile2() {
ipcRenderer.send('select-video').then((filePath) => {
if (filePath) {
console.log('Selected video path:', filePath);
// 你可以在这里添加更多处理逻辑,例如打开视频播放器界面等
} else {
console.log('No file was selected');
}
}).catch((error) => {
console.error('Failed to select video:', error);
});
}
function openVideoFile(file) {
const filePath = file.path; // 获取文件路径
ipcRenderer.send('open-video-file', filePath);
}