123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- /**
- * Copyright (c) 2012 Nokia Corporation.
- */
- import QtQuick 1.1
- import com.nokia.meego 1.0
- Item {
- id: videoPlayView
- // Enable/Disable rewinding/fast forwarding.
- property bool enableScrubbing: false
- // Set the video playback in either full or partial screen.
- property bool isFullScreen: false
- property bool isPortrait: visual.inPortrait
- // Video information data to be shown, when in partial screen mode.
- property string videoTitle: ""
- property int videoLength: 0
- property string videoAuthor: ""
- property int numLikes: 0
- property int numDislikes: 0
- property int viewCount: 0
- property string videoDescription: ""
- property string videoSource: ""
- property double topAreaProportion: visual.topAreaProportion
- property double bottomAreaProportion: visual.bottomAreaProportion
- property double leftAreaProportion: visual.leftAreaProportion
- property double rightAreaProportion: visual.rightAreaProportion
- // Ease of access handle for the VideoPlayerView Item.
- property alias videoPlayer: videoPlayerLoader.item
- // Property to observe the application shown/hidden status
- property bool applicationActive: Qt.application.active
- // Signalled, when exiting the Video player.
- signal videoExit
- // Function for setting the shown video information & setting the
- // video URL.
- function setVideoData(videoData) {
- videoPlayView.videoTitle = videoData.m_title ? videoData.m_title : "";
- videoPlayView.videoLength = videoData.m_duration ? videoData.m_duration : 0;
- videoPlayView.videoAuthor = videoData.m_author ? videoData.m_author : "";
- videoPlayView.numLikes = videoData.m_numLikes ? videoData.m_numLikes : 0;
- videoPlayView.numDislikes = videoData.m_numDislikes ? videoData.m_numDislikes : 0;
- videoPlayView.viewCount = videoData.m_viewCount ? videoData.m_viewCount : 0;
- videoPlayView.videoDescription = videoData.m_description ? videoData.m_description : "";
- // At least the m_contentUrl HAS to be defined!
- videoPlayView.videoSource = videoData.m_contentUrl;
- }
- function __showVideoControls(showControls) {
- overlayLoader.state = showControls ? "" : "Hidden";
- }
- function __toggleVideoControls() {
- // Disable automatic control hiding
- controlHideTimer.shouldRun = false;
- controlHideTimer.stop();
- if (overlayLoader.state == "") {
- overlayLoader.state = "Hidden";
- } else {
- overlayLoader.state = "";
- }
- }
- function __handleExit() {
- videoPlayer.stop();
- videoPlayer.disconnect();
- videoPlayView.videoExit();
- }
- function __playbackStarted() {
- controlHideTimer.startHideTimer();
- }
- Keys.onPressed: {
- if (!event.isAutoRepeat) {
- switch (event.key) {
- case Qt.Key_Right:
- console.log("TODO: Fast forward");
- event.accepted = true;
- break;
- case Qt.Key_Left:
- console.log("TODO: Reverse");
- event.accepted = true;
- break;
- case Qt.Key_Select:
- case Qt.Key_Enter:
- case Qt.Key_Return:
- if(videoPlayer.isPlaying) {
- videoPlayer.pause();
- } else {
- videoPlayer.play();
- }
- event.accepted = true;
- break;
- }
- }
- }
- // When going to background, pause the playback. And when returning from
- // background, resume playback.
- onApplicationActiveChanged: {
- if (videoPlayer) {
- if(applicationActive) {
- videoPlayer.play();
- } else {
- videoPlayer.pause();
- }
- }
- }
- anchors.fill: parent
- // A timer, which will give a small amount of time for the (page changing)
- // transitions to complete before the video loading is started. This is
- // done this way because otherwise the immediate loading of the video would
- // cause lagging & un-smooth animations.
- Timer {
- id: timer
- running: true
- interval: visual.animationDurationPrettyLong
- onTriggered: {
- stop();
- // The video playback area itself. Size for it is being determined
- // by the orientation and calculated proportionally based
- // on the parent dimensions.
- videoPlayerLoader.sourceComponent =
- Qt.createComponent("VideoPlayerView.qml");
- if (videoPlayerLoader.status === Loader.Ready) {
- if (videoPlayView.isFullScreen) {
- videoPlayer.toggled.connect(__toggleVideoControls);
- videoPlayer.playbackStarted.connect(__playbackStarted);
- }
- videoPlayer.stop();
- __showVideoControls(true);
- videoPlayer.source = videoPlayView.videoSource;
- videoPlayer.play();
- } else {
- console.log("Player loader NOT READY! Status: "
- + videoPlayerLoader.status);
- }
- }
- }
- // Timer responsible for hiding controls after entering
- // full screen player.
- Timer {
- id: controlHideTimer
- property bool shouldRun: videoPlayView.isFullScreen ? true : false
- function startHideTimer() {
- if (controlHideTimer.shouldRun) {
- start();
- }
- }
- running: false
- interval: visual.videoControlsHideTimeout
- onTriggered: {
- controlHideTimer.shouldRun = false;
- if (videoPlayer.isPlaying) {
- __showVideoControls(false);
- }
- }
- }
- Component {
- id: videoTitleComp
- VideoInfoTextLabel {
- maximumLineCount: isPortrait ? 2 : 1
- wrapMode: Text.WordWrap
- elide: Text.ElideRight
- text: videoPlayView.videoTitle
- font.bold: true
- }
- }
- // Loader, which selects what to show on the upper part of the screen.
- Loader {
- id: upperAreaLoader
- anchors {
- top: parent.top
- topMargin: videoPlayView.isFullScreen ? 0 : visual.margins
- left: parent.left
- leftMargin: videoPlayView.isFullScreen ? 0 : visual.margins
- right: parent.right
- }
- height: videoPlayView.isFullScreen ?
- 0 : (videoPlayView.height * topAreaProportion)
- sourceComponent: videoPlayView.isFullScreen ? undefined : videoTitleComp
- }
- // The Video can be played either in portrait or landscape mode. The
- // VideoInformationView is selected to be on the bottom when in portrait,
- // and when in landscape, the information is shown on the right side.
- Component {
- id: videoInformation
- VideoInformationView {
- videoTitle: videoPlayView.videoTitle
- numLikes: videoPlayView.numLikes
- numDislikes: videoPlayView.numDislikes
- viewCount: videoPlayView.viewCount
- }
- }
- // Loader, which selects what to show on the bottom part of the screen.
- Loader {
- id: bottomAreaLoader
- height: videoPlayView.isFullScreen ?
- 0 : (videoPlayView.height * bottomAreaProportion)
- width: videoPlayView.isFullScreen ? 0 : (videoPlayView.width / 3)
- anchors {
- bottom: parent.bottom
- bottomMargin: videoPlayView.isFullScreen ? 0 : visual.margins
- horizontalCenter: parent.horizontalCenter
- }
- sourceComponent: videoPlayView.isFullScreen ?
- undefined : (isPortrait ?
- videoInformation : undefined)
- }
- // In landscape there's an extra loader for the right side of the screen,
- // which will load basically the same information (views, likes & dislikes)
- // as in the upperAreaLoader in portrait mode.
- Loader {
- id: rightAreaLoader
- width: videoPlayView.isFullScreen ? 0 : (videoPlayView.width / 5)
- height: videoPlayView.isFullScreen ? 0 : videoPlayerLoader.height
- anchors {
- right: parent.right
- rightMargin: videoPlayView.isFullScreen ?
- 0 : (visual.isE6 ?
- visual.margins * 9 : visual.margins * 6)
- verticalCenter: videoPlayView.verticalCenter
- }
- sourceComponent: videoPlayView.isFullScreen ?
- undefined : (isPortrait ? undefined : videoInformation)
- }
- // Loader for the VideoPlayerComponent. NOTE: The sourceComponent will be
- // set a bit later, after the timer has triggered.
- Loader {
- id: videoPlayerLoader
- height: videoPlayView.isFullScreen ? screen.height : (videoPlayView.height
- * (1 - visual.topAreaProportion - visual.bottomAreaProportion))
- anchors {
- top: upperAreaLoader.bottom
- left: parent.left
- right: parent.right
- leftMargin: videoPlayView.isFullScreen ?
- 0 : (videoPlayView.width * visual.leftAreaProportion)
- rightMargin: videoPlayView.isFullScreen ?
- 0 : (videoPlayView.width * visual.rightAreaProportion)
- }
- }
- // Overlay controls on top of the video. Also always shown, when in
- // landscape and not in full screen video playback mode.
- Component {
- id: overlayComponent
- VideoPlayerControls {
- id: videoPlayerControls
- timePlayed: videoPlayer ? videoPlayer.timePlayed : 0
- timeDuration: videoPlayer ? videoPlayer.duration : 0
- isPlaying: videoPlayer ? videoPlayer.isPlaying : false
- enableScrubbing: videoPlayView.enableScrubbing
- onBackButtonPressed: {
- __handleExit();
- }
- onPausePressed: {
- videoPlayer.pause();
- }
- onPlayPressed: {
- videoPlayer.play();
- }
- onPlaybackPositionChanged: {
- videoPlayer.setPosition(playbackPosition);
- }
- }
- }
- // Loader for the overlay components, i.e. the VideoPlayerControls.
- Loader {
- id: overlayLoader
- state: "Hidden"
- sourceComponent: overlayComponent
- // Don't use anchoring here, use y-coordinate instead, so that
- // it can be animated.
- y: parent.height - visual.controlAreaHeight
- width: videoPlayView.width
- height: visual.controlAreaHeight
- states: [
- // Inactive state.
- State {
- name: "Hidden"
- PropertyChanges {
- target: overlayLoader
- // Move the controls 'beneath' the screen
- // and make it completely transparent.
- y: videoPlayView.height
- opacity: 0.0
- }
- }
- ]
- transitions: [
- // Transition between active and inactive states.
- Transition {
- from: ""; to: "Hidden"; reversible: true
- ParallelAnimation {
- PropertyAnimation {
- properties: "opacity"
- easing.type: Easing.InOutExpo
- duration: visual.animationDurationShort
- }
- PropertyAnimation {
- properties: "y"
- duration: visual.animationDurationNormal
- }
- }
- }
- ]
- }
- }
|