Warning, /plasma-bigscreen/youtube-voice-application/ui/+mediacenter/YoutubePlayerBB.qml is written in an unsupported language. File is not indexed.

0001 import QtAV 1.7
0002 import QtQuick.Layouts 1.4
0003 import QtQuick 2.9
0004 import QtQuick.Controls 2.0 as Controls
0005 import org.kde.kirigami 2.8 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.currenttitle
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     
0024     //The player is always fullscreen
0025     fillWidth: true
0026     background: Rectangle {
0027         color: "black"
0028     }
0029     leftPadding: 0
0030     topPadding: 0
0031     rightPadding: 0
0032     bottomPadding: 0
0033 
0034     onEnabledChanged: syncStatusTimer.restart()
0035     onVideoSourceChanged: syncStatusTimer.restart()
0036     Component.onCompleted: syncStatusTimer.restart()
0037     
0038     Keys.onShiftPressed: {
0039         console.log(parent.currentIndex)
0040     }
0041     
0042     function getViewCount(value){
0043         return value.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')
0044     }
0045     
0046     function setPublishedDate(publishDate){
0047         if(publishDate){
0048             var date1 = new Date(publishDate).getTime();
0049             var date2 = new Date().getTime();
0050             console.log(date1)
0051             console.log(date2)
0052             
0053             var msec = date2 - date1;
0054             var mins = Math.floor(msec / 60000);
0055             var hrs = Math.floor(mins / 60);
0056             var days = Math.floor(hrs / 24);
0057             var yrs = Math.floor(days / 365);
0058             mins = mins % 60;
0059             hrs = hrs % 24;
0060             days = days % 365;
0061             var result = "Published: " + days + " days, " + hrs + " hours, " + mins + " minutes ago"
0062             return result
0063         } else {
0064             return ""
0065         }
0066     }
0067 
0068     // Sometimes can't be restarted reliably immediately, put it in a timer
0069     Timer {
0070         id: syncStatusTimer
0071         interval: 0
0072         onTriggered: {
0073             if (enabled && videoStatus == "play") {
0074                 video.play();
0075             } else if (videoStatus == "stop") {
0076                 video.stop();
0077             } else {
0078                 video.pause();
0079             }
0080         }
0081     }
0082     
0083     Timer {
0084         id: delaytimer
0085     }
0086 
0087     function delay(delayTime, cb) {
0088             delaytimer.interval = delayTime;
0089             delaytimer.repeat = false;
0090             delaytimer.triggered.connect(cb);
0091             delaytimer.start();
0092     }
0093     
0094     controlBar: Local.SeekControl {
0095         id: seekControl
0096         anchors {
0097             left: parent.left
0098             right: parent.right
0099             bottom: parent.bottom
0100         }
0101         title: videoTitle  
0102         videoControl: video
0103         duration: video.duration
0104         playPosition: video.position
0105         onSeekPositionChanged: video.seek(seekPosition);
0106         z: 1000
0107     }
0108     
0109     Item {
0110         id: videoRoot
0111         anchors.fill: parent 
0112         focus: true
0113         
0114         Rectangle { 
0115             id: infomationBar 
0116             anchors.left: parent.left
0117             anchors.right: parent.right
0118             anchors.top: parent.top
0119             color: Qt.rgba(Kirigami.Theme.backgroundColor.r, Kirigami.Theme.backgroundColor.g, Kirigami.Theme.backgroundColor.b, 0.6)
0120             implicitHeight: infoLayout.implicitHeight + Kirigami.Units.largeSpacing * 2
0121             z: 1001
0122             
0123             onVisibleChanged: {
0124                 delay(15000, function() {
0125                     infomationBar.visible = false;
0126                 })
0127             }
0128             
0129             RowLayout {
0130                 id: infoLayout
0131                 anchors.fill: parent
0132                 
0133                 ColumnLayout {
0134                     Layout.fillWidth: true
0135                     Layout.fillHeight: true
0136                     Layout.alignment: Qt.AlignLeft
0137                     Layout.leftMargin: Kirigami.Units.largeSpacing
0138                     
0139                     Kirigami.Heading {
0140                         id: vidTitle
0141                         level: 2
0142                         height: Kirigami.Units.gridUnit * 2
0143                         visible: true
0144                         text: "Title: " + videoTitle
0145                         z: 100
0146                     }
0147                     
0148                     Kirigami.Heading {
0149                         id: vidAuthor
0150                         level: 2
0151                         height: Kirigami.Units.gridUnit * 2
0152                         visible: true
0153                         text: "Published By: " + videoAuthor
0154                         z: 100
0155                     }
0156                 }
0157                 
0158                 ColumnLayout {
0159                     Layout.fillWidth: true
0160                     Layout.fillHeight: true
0161                     Layout.alignment: Qt.AlignRight
0162                     Layout.rightMargin: Kirigami.Units.largeSpacing
0163                     
0164                     Kirigami.Heading {
0165                         id: vidCount
0166                         level: 2
0167                         height: Kirigami.Units.gridUnit * 2
0168                         visible: true
0169                         text: "Views: " + getViewCount(videoViewCount)
0170                         z: 100
0171                     }
0172                     
0173                     Kirigami.Heading {
0174                         id: vidPublishDate
0175                         level: 2
0176                             height: Kirigami.Units.gridUnit * 2
0177                         visible: true
0178                         text: setPublishedDate(videoPublishDate)
0179                         z: 100
0180                     }
0181                 }
0182             }
0183         }
0184         
0185         SuggestionArea {
0186             id: suggestArea
0187             videoSuggestionList: sessionData.videoListBlob.videoList
0188             z: 2000
0189             visible: false
0190         }
0191         
0192         Image {
0193             id: thumbart
0194             anchors.fill: parent
0195             fillMode: Image.PreserveAspectFit
0196             source: root.videoThumb 
0197             enabled: root.videoStatus == "stop" ? 1 : 0
0198             visible: root.videoStatus == "stop" ? 1 : 0
0199         }
0200         
0201         VideoOutput2 {
0202             opengl: true
0203             fillMode: VideoOutput.PreserveAspectFit
0204             source: video
0205             anchors.fill: parent
0206         }
0207 
0208         AVPlayer {
0209             id: video
0210             autoLoad: true
0211             autoPlay: false
0212             source: videoSource
0213             videoCodecPriority: ["FFmpeg", "VAAPI"]
0214 
0215             readonly property string currentStatus: root.enabled ? root.videoStatus : "pause"
0216 
0217             onCurrentStatusChanged: {print("OOO"+currentStatus)
0218             switch(currentStatus){
0219                 case "stop":
0220                     video.stop();
0221                     break;
0222                 case "pause":
0223                     video.pause()
0224                     break;
0225                 case "play":
0226                     video.play()
0227                     delay(15000, function() {
0228                         infomationBar.visible = false;
0229                     })
0230                     break;
0231                 }
0232             }
0233         }
0234         
0235         KeyNavigation.up: closeButton
0236         Keys.onSpacePressed: { 
0237             video.playbackState == MediaPlayer.PlayingState ? video.pause() : video.play()
0238             infomationBar.visible = true
0239         }
0240         Keys.onDownPressed: {
0241             controlBarItem.opened = true
0242             controlBarItem.forceActiveFocus()
0243         }
0244         
0245         MouseArea {
0246             anchors.fill: parent
0247             onClicked: {
0248                 infomationBar.visible = true;
0249                 controlBarItem.opened = !controlBarItem.opened 
0250             }
0251         }
0252     }
0253 }