-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPlayerWindow.qml
executable file
·304 lines (285 loc) · 8.47 KB
/
PlayerWindow.qml
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
import QtQuick 2.0
import QtMultimedia 5.9
import QtQuick.Dialogs 1.3
import Qt.labs.folderlistmodel 2.2
import QtQuick.Controls 2.3
import QtQuick.Layouts 1.3
SystemWindow {
id: root
width: def.win_width
height: def.win_height
// title: qsTr("视频")
// flags: Qt.Dialog //Dialog,没有最大最小化按钮
// //第一次打开时才会重新加载
// function show()
// {
// open()
// }
// property bool showFlag: false
// onAboutToHide: showFlag = false
onVisibleChanged: {
if(showFlag == false)
{
showFlag = true;
// console.log("视频窗口被激活")
setVideoPath(def.videoDefaultLocation)
}
}
Define {
id: def
source_url: video.source
}
// //最底层背景图片
// Image {
// id: backgroundImage
// anchors.fill: parent
// width: parent.width
// height: parent.height
// source: def.url_video_background
// fillMode: Image.PreserveAspectFit
// clip: true
// }
//视频输出到背景
VideoOutput {
anchors.fill: parent //充满背景
source: video
}
//左上角返回按钮显示视频名称
MyIconButton {
id: backButton
icon_code: def.iconCode_back
button_text: video.hasVideo ? def.getFileName() : "返回"
button_color: "white"
anchors.left: parent.left
anchors.top: parent.top
anchors.margins: 10
onClicked: {
videoStop()
root.close()
}
}
//右上角选择视频文件夹按钮
MyIconButton {
id: openButton
icon_code: def.iconCode_folder
button_text: qsTr("打开文件")
button_color: "white"
anchors.right: parent.right
anchors.top: parent.top
anchors.margins: 10
onClicked:
{
if(video.hasVideo)
videoPause()
// fileDialog.open()
fileBrowser.nameFilter = def.videoNameFilters
fileBrowser.defaultLocation = def.videoDefaultLocation
fileBrowser.showNormal()
}
}
PlayerControlBar {
id: player
visible: true
width: def.win_width
enabled: video.hasVideo & (folderModel.count!=0)
anchors.bottom: parent.bottom
media_duration: video.duration
onClicked_play:videoPlay()
onClicked_pause: videoPause()
onClicked_stop: videoStop()
onClicked_step_backward: videoStepBackward()
onClicked_step_forward: videoStepForward()
onClicked_backward: videoBackward()
onClicked_forward: videoForward()
hourFlag: true //时间标签带小时
onMoved_slider:
{
video.seek(slider_value)
videoPlay()
}
}
//鼠标进入现实,鼠标退出隐藏的效果实现
/*
MouseArea {
width: player.width
height: player.height
anchors.bottom: parent.bottom
propagateComposedEvents: true
hoverEnabled: true
onEntered: player.visible = true
onExited: player.visible = false
}
*/
function videoPlay()
{
player.playing = true;
video.play();
}
function videoPause()
{
player.playing = false;
video.pause();
}
function videoStop()
{
videoSwitchFlag = true;
player.playing = false;
player.media_postion = 0;
video.stop();
videoSwitchFlag = false;
}
function videoStepForward()
{
video.seek(video.position+10000)
}
function videoStepBackward()
{
video.seek(video.position-10000)
}
function videoBackward()
{
videoSwitchFlag = true;
videoStop();
videoIndex -= 1;
if(videoIndex < 0)
videoIndex = getVideoCount()-1;//-1->4
video.source = getVideoURL(videoIndex)
console.log("上一曲:" + (videoIndex+1) + "/" + getVideoCount() + ":" + video.source);
videoPlay();
videoSwitchFlag = false;
}
function videoForward()
{
videoSwitchFlag = true;
videoStop();
videoIndex += 1;
if(videoIndex == getVideoCount()) //0-4, 5
videoIndex = 0; //4->0
video.source = getVideoURL(videoIndex)
console.log("下一曲:" + (videoIndex+1) + "/" + getVideoCount() + ":" + video.source);
videoPlay();
videoSwitchFlag = false;
}
//暂停时,视频中央显示的大按钮
MyToolButton {
id: btn_play2
enabled: video.hasVideo & (folderModel.count!=0)
icon_code: def.iconCode_pause
icon_size: 40
icon_color: "#ffffff"
color: "lightslategray"
clr_exited: "darkgray"
clr_entered: "teal"
width: 80
height: 80
anchors.centerIn: parent
onClicked: videoPlay()
visible: player.playing ? false : true
}
//视频区域单击暂停播放切换
MouseArea {
enabled: video.hasVideo && (getVideoCount() > 0)
anchors.top: backButton.bottom
anchors.bottom: player.top
anchors.left: parent.left
anchors.right: parent.right
anchors.rightMargin: 50
onClicked: player.playing ? videoPause() : videoPlay();
}
//视频播放器
MediaPlayer {
id: video
volume: player.media_volume
onPositionChanged: player.media_postion = video.position
onPlaybackStateChanged: //1:playing, 2:pause, 0:stop
{
if(video.playbackState == MediaPlayer.StoppedState ) //播放完成自动停止
{
if(videoSwitchFlag == false)
{
console.log("video stop")
videoForward(); //自动播放下一个
}
}
}
}
FolderListModel {
id: folderModel
objectName: "folderModel"
showDirs: false
nameFilters: def.videoNameFilters
sortField: FolderListModel.Name
// onStatusChanged: console.log("status:", folderModel.status);
onFolderChanged: {
if(getVideoCount() == 0) {
console.log("所选文件夹无视频文件:" + folderModel.folder)
videoIndex = 0;
}
else {
console.log("共发现" + getVideoCount() + "个视频文件")
videoSwitchFlag = true;
videoIndex = 0;
video.source = getVideoURL(videoIndex)
videoSwitchFlag = false;
}
}
}
//文件选择对话框,调用系统自带的窗口
/*
FileDialog {
id: fileDialog
title: "请选择一个视频文件夹"
selectFolder: true //只能选择文件夹
onRejected: {
if(video.hasVideo)
videoPlay()
}
//设置folderModel的文件夹为当前选定的文件夹
onAccepted: {
videoIndex = 0;
setVideoPath(fileUrl + "/")
}
}*/
//自定义文件浏览器
FileList{
id: fileBrowser
backButtonText: root.title
onRejected: {
if(video.hasVideo)
videoPlay()
}
onAccepted: {
videoSwitchFlag = true;
videoIndex = fileBrowser.fileIndex
console.log(videoIndex)
video.source = getVideoURL(videoIndex)
setVideoPath(fileUrl + "/");
console.log("设置视频文件夹为:", fileUrl + "/");
videoSwitchFlag = false
}
}
function setVideoPath(path)
{
folderModel.folder = path;
}
function getVideoURL(idx)
{
var path = "file://";
var filepath = folderModel.get(idx, "filePath")
// if (filepath[1] === ':') // Windows drive logic, see QUrl::fromLocalFile()
// path += '/';
path += filepath;
console.log(path)
return path;
}
function getVideoFolder()
{
return folderModel.folder
}
function getVideoCount()
{
return folderModel.count
}
property int videoIndex: 0
property bool videoSwitchFlag: false
}