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