Warning, /plasma-bigscreen/peertube-voice-application/ui/PeerTubePlayer.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_stream
0016     property var videoStatus: sessionData.video_status
0017     property var videoThumb: "https://" + sessionData.video_meta.channel.host + sessionData.video_meta.thumbnail_path
0018     property var videoTitle: sessionData.video_meta.name
0019     property var videoAuthor: sessionData.video_meta.channel.name
0020     property var videoViewCount: sessionData.video_meta.views
0021     property var videoPublishDate: sessionData.video_meta.published_at
0022     property bool busyIndicate: false
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: {
0037         syncStatusTimer.restart()
0038     }
0039     
0040     function changePage(){
0041         delay(3500, function() {
0042             parent.parent.parent.currentIndex++
0043             parent.parent.parent.currentItem.contentItem.forceActiveFocus()
0044         })
0045     }
0046     
0047     onVideoThumbChanged: {
0048         if(videoThumb == ""){
0049             busyIndicatorPop.open()
0050         } else {
0051             busyIndicatorPop.close()
0052         }
0053     }
0054     
0055     Keys.onDownPressed: {
0056         controlBarItem.opened = true
0057         controlBarItem.forceActiveFocus()
0058     }
0059             
0060     onFocusChanged: {
0061         if(focus){
0062             video.forceActiveFocus();
0063         }
0064     }
0065     
0066     Connections {
0067         target: window
0068         onVisibleChanged: {
0069             if(video.playbackState == MediaPlayer.PlayingState) {
0070                 videoStatus = "stop"
0071                 video.stop()
0072             }
0073         }
0074     }
0075     
0076     function getViewCount(value){
0077         return value.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')
0078     }
0079     
0080     function setPublishedDate(publishDate) {
0081         var date1 = new Date(publishDate).getTime();
0082         var date2 = new Date().getTime();
0083         console.log(date1)
0084         console.log(date2)
0085         
0086         var msec = date2 - date1;
0087         var mins = Math.floor(msec / 60000);
0088         var hrs = Math.floor(mins / 60);
0089         var days = Math.floor(hrs / 24);
0090         var yrs = Math.floor(days / 365);
0091         mins = mins % 60;
0092         hrs = hrs % 24;
0093         days = days % 365;
0094         var result = ""
0095         if(days == 0 && hrs > 0) {
0096             result = hrs + " hours, " + mins + " minutes ago"
0097         } else if (days == 0 && hrs == 0) {
0098             result = mins + " minutes ago"
0099         } else {
0100             result = days + " days, " + hrs + " hours, " + mins + " minutes ago"
0101         }
0102         return result
0103     }
0104 
0105     function listProperty(item) {
0106         for (var p in item)
0107         {
0108             if( typeof item[p] != "function" )
0109                 if(p != "objectName")
0110                     console.log(p + ":" + item[p]);
0111         }
0112     }
0113     
0114     // Sometimes can't be restarted reliably immediately, put it in a timer
0115     Timer {
0116         id: syncStatusTimer
0117         interval: 0
0118         onTriggered: {
0119             if (enabled && videoStatus == "play") {
0120                 video.play();
0121             } else if (videoStatus == "stop") {
0122                 video.stop();
0123             } else {
0124                 video.pause();
0125             }
0126         }
0127     }
0128     
0129     Timer {
0130         id: delaytimer
0131     }
0132 
0133     function delay(delayTime, cb) {
0134             delaytimer.interval = delayTime;
0135             delaytimer.repeat = false;
0136             delaytimer.triggered.connect(cb);
0137             delaytimer.start();
0138     }
0139     
0140     controlBar: Local.SeekControl {
0141         id: seekControl
0142         anchors {
0143             left: parent.left
0144             right: parent.right
0145             bottom: parent.bottom
0146         }
0147         title: videoTitle  
0148         videoControl: video
0149         duration: video.duration
0150         playPosition: video.position
0151         onSeekPositionChanged: video.seek(seekPosition);
0152         z: 1000
0153     }
0154     
0155     Item {
0156         id: videoRoot
0157         anchors.fill: parent 
0158             
0159          Rectangle { 
0160             id: infomationBar 
0161             anchors.left: parent.left
0162             anchors.right: parent.right
0163             anchors.top: parent.top
0164             visible: false
0165             color: Qt.rgba(Kirigami.Theme.backgroundColor.r, Kirigami.Theme.backgroundColor.g, Kirigami.Theme.backgroundColor.b, 0.6)
0166             implicitHeight: vidTitle.implicitHeight + Kirigami.Units.largeSpacing * 2
0167             z: 1001
0168             
0169             onVisibleChanged: {
0170                 delay(15000, function() {
0171                     infomationBar.visible = false;
0172                 })
0173             }
0174             
0175             Kirigami.Heading {
0176                 id: vidTitle
0177                 level: 2
0178                 height: Kirigami.Units.gridUnit * 2
0179                 visible: true
0180                 anchors.verticalCenter: parent.verticalCenter
0181                 text: "Title: " + videoTitle
0182                 z: 100
0183             }
0184          }
0185             
0186         Image {
0187             id: thumbart
0188             anchors.fill: parent
0189             fillMode: Image.PreserveAspectFit
0190             source: root.videoThumb 
0191             enabled: root.videoStatus == "stop" ? 1 : 0
0192             visible: root.videoStatus == "stop" ? 1 : 0
0193         }
0194         
0195         Controls.Popup {
0196             id: busyIndicatorPop
0197             x: (parent.width - width) / 2
0198             y: (parent.height - height) / 2
0199             
0200             background: Rectangle {
0201                 anchors.fill: parent
0202                 color: Qt.rgba(0, 0, 0, 0.5)
0203             }
0204             closePolicy: Controls.Popup.CloseOnEscape | Controls.Popup.CloseOnPressOutsideParent
0205             
0206             RowLayout {
0207                 anchors.centerIn: parent
0208 
0209                 Controls.BusyIndicator {
0210                     running: busyIndicate
0211                 }
0212                 
0213                 Kirigami.Heading {
0214                     level: 2
0215                     text: "Searching Video"
0216                 }
0217             }
0218             
0219             onOpened: {
0220                 busyIndicate = true
0221             }
0222             
0223             onClosed: {
0224                 busyIndicate = false
0225             }
0226         }
0227         
0228         Video {
0229             id: video
0230             anchors.fill: parent
0231             focus: true
0232             autoLoad: true
0233             autoPlay: false
0234             Keys.onSpacePressed: video.playbackState == MediaPlayer.PlayingState ? video.pause() : video.play()
0235             KeyNavigation.up: closeButton
0236             source: videoSource
0237             readonly property string currentStatus: root.enabled ? root.videoStatus : "pause"
0238             
0239             onCurrentStatusChanged: {print("OOO"+currentStatus)
0240                 switch(currentStatus){
0241                     case "stop":
0242                         video.stop();
0243                         break;
0244                     case "pause":
0245                         video.pause()
0246                         break;
0247                     case "play":
0248                         video.play()
0249                         busyIndicatorPop.close()
0250                         delay(6000, function() {
0251                             infomationBar.visible = false;
0252                         })
0253                         break;
0254                 }
0255             }
0256             
0257             Keys.onReturnPressed: {
0258                 video.playbackState == MediaPlayer.PlayingState ? video.pause() : video.play()
0259             }
0260                     
0261             Keys.onDownPressed: {
0262                 controlBarItem.opened = true
0263                 controlBarItem.forceActiveFocus()
0264             }
0265             
0266             MouseArea {
0267                 anchors.fill: parent
0268                 onClicked: { 
0269                     controlBarItem.opened = !controlBarItem.opened 
0270                 }
0271             }
0272             
0273             onStatusChanged: {
0274                 console.log(status)
0275                 if(status == 7) {
0276                     changePage()
0277                 }
0278             }
0279         }
0280     }
0281 }