forked from anatolyk82/ShaderTransitionView
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSTVideoView.qml
211 lines (175 loc) · 5.58 KB
/
STVideoView.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
import QtQuick 2.0
import "private"
import QtMultimedia 5.5
import ShaderTransitionView 1.0
ShaderTransitionView {
id: root
property int duration: 1000
property var itemList: []
property int depth: 0
property string currentItem: ""
property var shaderEffectOptions: { "progress":0.0 }
transition: "Wind"
property variant videoOutput: videoOutputCurrent
property variant mediaPlayer: playerCurrent
property bool __softChangingOfVolume: false
property bool autoPlay: mediaPlayer.autoPlay
function push( itemPath )
{
itemList.push( itemPath )
currentItem = itemPath
depth = itemList.length
if( itemList.length > 1 ) {
if( (itemList.length % 2) == 0 ) {
playerNext.source = itemPath
mediaPlayer = playerNext
videoOutput = videoOutputNext
} else {
playerCurrent.source = itemPath
mediaPlayer = playerCurrent
videoOutput = videoOutputCurrent
}
loaderShaderEffect.setSource( __graphEffect(), shaderEffectOptions )
} else {
playerCurrent.source = itemPath
mediaPlayer = playerCurrent
videoOutput = videoOutputCurrent
}
}
function pop()
{
if( itemList.length > 1 ) {
itemList.pop()
depth = itemList.length
if( (itemList.length % 2) == 0 ) {
playerNext.source = itemList[ (itemList.length-1) ]
currentItem = playerNext.source
mediaPlayer = playerNext
videoOutput = videoOutputNext
} else {
playerCurrent.source = itemList[ (itemList.length-1) ]
currentItem = playerCurrent.source
mediaPlayer = playerCurrent
videoOutput = videoOutputCurrent
}
loaderShaderEffect.setSource( __graphEffect(), shaderEffectOptions )
}
}
function clear()
{
itemList.splice( 0, itemList.length )
depth = itemList.length
}
function __graphEffect()
{
return "TransitionEffects/" + transition + ".qml";
}
property real progress: 0.0
SequentialAnimation on progress {
id: animProgress
running: false
ScriptAction {
script: {
}
}
PropertyAnimation {
from: 0.0
to: 1.0
duration: root.duration
}
ScriptAction {
script: {
if( (itemList.length % 2) ) {
playerNext.source = ""
} else {
playerCurrent.source = ""
}
loaderShaderEffect.source = ""
shaderEffectOptions = { "progress":0.0 }
__softChangingOfVolume = false
}
}
}
//*******************************************************//
MediaPlayer {
id: playerCurrent
autoPlay: true
/*onStatusChanged: {
if(status == MediaPlayer.NoMedia) {
console.log("No media has been set.")
} else if(status == MediaPlayer.InvalidMedia) {
console.log("The media cannot be played.")
}
}
onPlaybackStateChanged: {
if( playbackState == MediaPlayer.PlayingState ) {
console.log("CURRENT: playing")
}
}*/
Behavior on volume { NumberAnimation { duration: __softChangingOfVolume ? root.duration : 0 } }
}
VideoOutput {
id: videoOutputCurrent
source: playerCurrent
anchors.fill: parent
}
//*******************************************************//
MediaPlayer {
id: playerNext
autoPlay: true
/*onStatusChanged: {
if(status == MediaPlayer.NoMedia) {
console.log("No media has been set.")
} else if(status == MediaPlayer.InvalidMedia) {
console.log("The media cannot be played.")
}
}
onPlaybackStateChanged: {
if( playbackState == MediaPlayer.PlayingState ) {
console.log("NEXT: playing")
}
}*/
Behavior on volume { NumberAnimation { duration: __softChangingOfVolume ? root.duration : 0 } }
}
VideoOutput {
id: videoOutputNext
source: playerNext
anchors.fill: parent
}
//*******************************************************//
ShaderEffectSource {
id: textureSource
hideSource: false
}
ShaderEffectSource {
id: textureDestination
hideSource: false
}
Loader {
id: loaderShaderEffect
anchors.fill: parent
onLoaded: {
__softChangingOfVolume = true
if( (itemList.length % 2) == 0 ) {
textureSource.sourceItem = videoOutputCurrent
textureDestination.sourceItem = videoOutputNext
playerCurrent.volume = 0
playerNext.volume = 1
} else {
textureSource.sourceItem = videoOutputNext
textureDestination.sourceItem = videoOutputCurrent
playerCurrent.volume = 1
playerNext.volume = 0
}
item.srcSampler = textureSource
item.dstSampler = textureDestination
root.progress = 0.0
animProgress.restart()
}
}
Binding {
target: loaderShaderEffect.item
property: "progress"
value: root.progress
}
}