Warning, /plasma-bigscreen/youtube-voice-application/ui/+android/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 onFocusChanged: {
0054 console.log("here")
0055 if(focus && suggestions.visible){
0056 console.log("in suggestFocus 1")
0057 suggestions.forceActiveFocus();
0058 } else if(focus && !suggestions.visbile) {
0059 video.forceActiveFocus();
0060 }
0061 }
0062
0063 Connections {
0064 target: window
0065 onVisibleChanged: {
0066 if(video.playbackState == MediaPlayer.PlayingState) {
0067 video.stop()
0068 }
0069 }
0070 }
0071
0072 function getViewCount(value){
0073 return value.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')
0074 }
0075
0076 function setPublishedDate(publishDate){
0077 var date1 = new Date(publishDate).getTime();
0078 var date2 = new Date().getTime();
0079 console.log(date1)
0080 console.log(date2)
0081
0082 var msec = date2 - date1;
0083 var mins = Math.floor(msec / 60000);
0084 var hrs = Math.floor(mins / 60);
0085 var days = Math.floor(hrs / 24);
0086 var yrs = Math.floor(days / 365);
0087 mins = mins % 60;
0088 hrs = hrs % 24;
0089 days = days % 365;
0090 var result = "Published: " + days + " days, " + hrs + " hours, " + mins + " minutes ago"
0091 return result
0092 }
0093
0094 function listProperty(item){
0095 for (var p in item)
0096 {
0097 if( typeof item[p] != "function" )
0098 if(p != "objectName")
0099 console.log(p + ":" + item[p]);
0100 }
0101 }
0102
0103 // Sometimes can't be restarted reliably immediately, put it in a timer
0104 Timer {
0105 id: syncStatusTimer
0106 interval: 0
0107 onTriggered: {
0108 if (enabled && videoStatus == "play") {
0109 video.play();
0110 } else if (videoStatus == "stop") {
0111 video.stop();
0112 } else {
0113 video.pause();
0114 }
0115 }
0116 }
0117
0118 Timer {
0119 id: delaytimer
0120 }
0121
0122 function delay(delayTime, cb) {
0123 delaytimer.interval = delayTime;
0124 delaytimer.repeat = false;
0125 delaytimer.triggered.connect(cb);
0126 delaytimer.start();
0127 }
0128
0129 controlBar: Local.SeekControl {
0130 id: seekControl
0131 anchors {
0132 // left: parent.left
0133 // right: parent.right
0134 bottom: parent.bottom
0135 }
0136 title: videoTitle
0137 videoControl: video
0138 duration: video.duration
0139 playPosition: video.position
0140 onSeekPositionChanged: video.seek(seekPosition);
0141 z: 1000
0142 }
0143
0144 Item {
0145 id: videoRoot
0146 anchors.fill: parent
0147
0148 Rectangle {
0149 id: infomationBar
0150 anchors.left: parent.left
0151 anchors.right: parent.right
0152 anchors.top: parent.top
0153 visible: false
0154 color: Qt.rgba(Kirigami.Theme.backgroundColor.r, Kirigami.Theme.backgroundColor.g, Kirigami.Theme.backgroundColor.b, 0.6)
0155 implicitHeight: vidTitle.implicitHeight + Kirigami.Units.largeSpacing * 2
0156 z: 1001
0157
0158 onVisibleChanged: {
0159 delay(15000, function() {
0160 infomationBar.visible = false;
0161 })
0162 }
0163
0164 Controls.Label {
0165 id: vidTitle
0166 visible: true
0167 maximumLineCount: 2
0168 wrapMode: Text.Wrap
0169 anchors.left: parent.left
0170 anchors.leftMargin: Kirigami.Units.largeSpacing
0171 anchors.verticalCenter: parent.verticalCenter
0172 text: videoTitle
0173 z: 100
0174 }
0175 }
0176
0177 Image {
0178 id: thumbart
0179 anchors.fill: parent
0180 fillMode: Image.PreserveAspectFit
0181 source: root.videoThumb
0182 enabled: root.videoStatus == "stop" ? 1 : 0
0183 visible: root.videoStatus == "stop" ? 1 : 0
0184 }
0185
0186 SuggestionArea {
0187 id: suggestions
0188 visible: false
0189 videoSuggestionList: videoListModel
0190 nxtSongBlob: nextSongBlob
0191 onVisibleChanged: {
0192 if(visible) {
0193 suggestionListFocus = true
0194 } else {
0195 video.focus = true
0196 }
0197 }
0198 }
0199
0200 Video {
0201 id: video
0202 anchors.fill: parent
0203 focus: true
0204 autoLoad: true
0205 autoPlay: false
0206 Keys.onSpacePressed: video.playbackState == MediaPlayer.PlayingState ? video.pause() : video.play()
0207 KeyNavigation.up: closeButton
0208 //Keys.onLeftPressed: video.seek(video.position - 5000)
0209 //Keys.onRightPressed: video.seek(video.position + 5000)
0210 source: videoSource
0211 readonly property string currentStatus: root.enabled ? root.videoStatus : "pause"
0212
0213 onFocusChanged: {
0214 if(focus){
0215 console.log("focus in video")
0216 if(suggestions.visbile){
0217 console.log("in suggestFocus 2")
0218 suggestions.forceActiveFocus();
0219 }
0220 }
0221 }
0222
0223 onCurrentStatusChanged: {print("OOO"+currentStatus)
0224 switch(currentStatus){
0225 case "stop":
0226 video.stop();
0227 break;
0228 case "pause":
0229 video.pause()
0230 break;
0231 case "play":
0232 video.play()
0233 delay(6000, function() {
0234 infomationBar.visible = false;
0235 })
0236 break;
0237 }
0238 }
0239
0240 Keys.onReturnPressed: {
0241 video.playbackState == MediaPlayer.PlayingState ? video.pause() : video.play()
0242 }
0243
0244 Keys.onDownPressed: {
0245 controlBarItem.opened = true
0246 controlBarItem.forceActiveFocus()
0247 }
0248
0249 MouseArea {
0250 anchors.fill: parent
0251 onClicked: {
0252 controlBarItem.opened = !controlBarItem.opened
0253 }
0254 }
0255
0256 onStatusChanged: {
0257 if(status == MediaPlayer.EndOfMedia) {
0258 triggerGuiEvent("YoutubeSkill.NextAutoPlaySong", {})
0259 suggestions.visible = true
0260 } else {
0261 suggestions.visible = false
0262 }
0263 }
0264 }
0265 }
0266 }