Warning, /plasma-bigscreen/youtube-voice-application/ui/YoutubePlayer.qml is written in an unsupported language. File is not indexed.
0001 import QtMultimedia 5.12
0002 import QtQuick.Layouts 1.4
0003 import QtQuick 2.9
0004 import QtQuick.Controls 2.12 as Controls
0005 import org.kde.kirigami 2.10 as Kirigami
0006 import QtGraphicalEffects 1.0
0007
0008 import Mycroft 1.0 as Mycroft
0009
0010 import "." as Local
0011
0012 Mycroft.Delegate {
0013 id: root
0014
0015 property var videoSource: sessionData.video
0016 property var videoStatus: sessionData.status
0017 property var videoThumb: sessionData.videoThumb
0018 property var videoTitle: sessionData.setTitle
0019 property var videoAuthor: sessionData.videoAuthor
0020 property var videoViewCount: sessionData.viewCount
0021 property var videoPublishDate: sessionData.publishedDate
0022 property var videoListModel: sessionData.videoListBlob.videoList
0023 property var nextSongBlob: sessionData.nextSongBlob
0024
0025 //The player is always fullscreen
0026 fillWidth: true
0027 background: Rectangle {
0028 color: "black"
0029 }
0030 leftPadding: 0
0031 topPadding: 0
0032 rightPadding: 0
0033 bottomPadding: 0
0034
0035 onEnabledChanged: syncStatusTimer.restart()
0036 onVideoSourceChanged: syncStatusTimer.restart()
0037 Component.onCompleted: {
0038 syncStatusTimer.restart()
0039 }
0040
0041 Keys.onDownPressed: {
0042 controlBarItem.opened = true
0043 controlBarItem.forceActiveFocus()
0044 }
0045
0046 onVideoTitleChanged: {
0047 triggerGuiEvent("YoutubeSkill.RefreshWatchList", {"title": videoTitle})
0048 if(videoTitle != ""){
0049 infomationBar.visible = true
0050 }
0051 }
0052
0053 Connections {
0054 target: window
0055 onVisibleChanged: {
0056 if(video.playbackState == MediaPlayer.PlayingState) {
0057 video.stop()
0058 }
0059 }
0060 }
0061
0062 function getViewCount(value){
0063 return value.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')
0064 }
0065
0066 function setPublishedDate(publishDate){
0067 var date1 = new Date(publishDate).getTime();
0068 var date2 = new Date().getTime();
0069 console.log(date1)
0070 console.log(date2)
0071
0072 var msec = date2 - date1;
0073 var mins = Math.floor(msec / 60000);
0074 var hrs = Math.floor(mins / 60);
0075 var days = Math.floor(hrs / 24);
0076 var yrs = Math.floor(days / 365);
0077 mins = mins % 60;
0078 hrs = hrs % 24;
0079 days = days % 365;
0080 var result = "Published: " + days + " days, " + hrs + " hours, " + mins + " minutes ago"
0081 return result
0082 }
0083
0084 function listProperty(item){
0085 for (var p in item)
0086 {
0087 if( typeof item[p] != "function" )
0088 if(p != "objectName")
0089 console.log(p + ":" + item[p]);
0090 }
0091 }
0092
0093 // Sometimes can't be restarted reliably immediately, put it in a timer
0094 Timer {
0095 id: syncStatusTimer
0096 interval: 0
0097 onTriggered: {
0098 if (enabled && videoStatus == "play") {
0099 video.play();
0100 } else if (videoStatus == "stop") {
0101 video.stop();
0102 } else {
0103 video.pause();
0104 }
0105 }
0106 }
0107
0108 Timer {
0109 id: delaytimer
0110 }
0111
0112 function delay(delayTime, cb) {
0113 delaytimer.interval = delayTime;
0114 delaytimer.repeat = false;
0115 delaytimer.triggered.connect(cb);
0116 delaytimer.start();
0117 }
0118
0119 controlBar: Local.SeekControl {
0120 id: seekControl
0121 anchors {
0122 bottom: parent.bottom
0123 }
0124 title: videoTitle
0125 videoControl: video
0126 duration: video.duration
0127 playPosition: video.position
0128 onSeekPositionChanged: video.seek(seekPosition);
0129 z: 1000
0130 }
0131
0132 Item {
0133 id: videoRoot
0134 anchors.fill: parent
0135
0136 Rectangle {
0137 id: infomationBar
0138 anchors.left: parent.left
0139 anchors.right: parent.right
0140 anchors.top: parent.top
0141 visible: false
0142 color: Qt.rgba(Kirigami.Theme.backgroundColor.r, Kirigami.Theme.backgroundColor.g, Kirigami.Theme.backgroundColor.b, 0.6)
0143 implicitHeight: vidTitle.implicitHeight + Kirigami.Units.largeSpacing * 2
0144 z: 1001
0145
0146 onVisibleChanged: {
0147 delay(15000, function() {
0148 infomationBar.visible = false;
0149 })
0150 }
0151
0152 Controls.Label {
0153 id: vidTitle
0154 visible: true
0155 maximumLineCount: 2
0156 wrapMode: Text.Wrap
0157 anchors.left: parent.left
0158 anchors.leftMargin: Kirigami.Units.largeSpacing
0159 anchors.verticalCenter: parent.verticalCenter
0160 text: videoTitle
0161 z: 100
0162 }
0163 }
0164
0165 Image {
0166 id: thumbart
0167 anchors.fill: parent
0168 fillMode: Image.PreserveAspectFit
0169 source: root.videoThumb
0170 enabled: root.videoStatus == "stop" ? 1 : 0
0171 visible: root.videoStatus == "stop" ? 1 : 0
0172 }
0173
0174 Video {
0175 id: video
0176 anchors.fill: parent
0177 focus: true
0178 autoLoad: true
0179 autoPlay: false
0180 Keys.onSpacePressed: video.playbackState == MediaPlayer.PlayingState ? video.pause() : video.play()
0181 KeyNavigation.up: closeButton
0182 source: videoSource
0183 readonly property string currentStatus: root.enabled ? root.videoStatus : "pause"
0184
0185 onCurrentStatusChanged: {print("OOO"+currentStatus)
0186 switch(currentStatus){
0187 case "stop":
0188 video.stop();
0189 break;
0190 case "pause":
0191 video.pause()
0192 break;
0193 case "play":
0194 video.play()
0195 delay(6000, function() {
0196 infomationBar.visible = false;
0197 })
0198 break;
0199 }
0200 }
0201
0202 Keys.onReturnPressed: {
0203 video.playbackState == MediaPlayer.PlayingState ? video.pause() : video.play()
0204 }
0205
0206 Keys.onDownPressed: {
0207 controlBarItem.opened = true
0208 controlBarItem.forceActiveFocus()
0209 }
0210
0211 MouseArea {
0212 anchors.fill: parent
0213 onClicked: {
0214 controlBarItem.opened = !controlBarItem.opened
0215 }
0216 }
0217
0218 onStatusChanged: {
0219 if(status == MediaPlayer.EndOfMedia) {
0220 triggerGuiEvent("YoutubeSkill.NextAutoPlaySong", {})
0221 }
0222 }
0223 }
0224 }
0225 }