-
Notifications
You must be signed in to change notification settings - Fork 0
/
AudioPlayback.qml
61 lines (61 loc) · 1.93 KB
/
AudioPlayback.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
import QtQuick
import QtMultimedia
import QtQuick.Controls
Rectangle{
id: root
height: mediaPlayerUI.implicitHeight
// width: mediaPlayerUI.implicitWidth
color: "grey"
property var source_audio;
MediaPlayer{
id: mediaPlayer
source: root.source_audio
audioOutput: AudioOutput{}
}
Row{
id: mediaPlayerUI
spacing: 10
Image{
id: playpausebutton
source: mediaPlayer.playbackState === MediaPlayer.PlayingState ? "assets/photo/pause.png" : "assets/photo/play.png"
width: (root.width-20)*0.25; height: playpausebutton.width
MouseArea{
anchors.fill:parent
onClicked: {
if (mediaPlayer.playbackState === MediaPlayer.PlayingState)
mediaPlayer.pause()
else
mediaPlayer.play()
}
}
}
Slider{
id: audioSlider
width: (root.width-20)*0.5
from: 0
anchors.verticalCenter: parent.verticalCenter
to: mediaPlayer.duration
value: mediaPlayer.position
onValueChanged: {
if(mediaPlayer.position != audioSlider.value)
mediaPlayer.position = audioSlider.value
}
}
Text{
id: durationText
width: (root.width-20)*0.25
text: formatTime(mediaPlayer.position)
anchors.verticalCenter: parent.verticalCenter
function formatTime(milliseconds){
var seconds = Math.floor(milliseconds/1000)
var minutes = Math.floor(seconds/60)
seconds %= 60
if(seconds < 10)
seconds = "0"+seconds
if(minutes < 10)
minutes = "0"+minutes
return minutes+":"+seconds
}
}
}
}