VideoPlayerView.qml 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /**
  2. * Copyright (c) 2012 Nokia Corporation.
  3. */
  4. import QtQuick 1.1
  5. import com.nokia.meego 1.0
  6. import QtMobility.systeminfo 1.1
  7. import QtMultimediaKit 1.1
  8. Item {
  9. id: videoPlayerContainer
  10. property alias source: videoPlayerImpl.source
  11. property alias duration: videoPlayerImpl.duration
  12. property alias timePlayed: videoPlayerImpl.position
  13. property alias volume: videoPlayerImpl.volume
  14. property int timeRemaining: videoPlayerImpl.duration - timePlayed
  15. property bool isPlaying: false
  16. signal toggled
  17. signal playbackStarted
  18. function play() {
  19. videoPlayerImpl.play();
  20. }
  21. function stop() {
  22. videoPlayerImpl.stop();
  23. }
  24. function pause() {
  25. videoPlayerImpl.pause();
  26. }
  27. function disconnect() {
  28. volumeConnections.target = null;
  29. }
  30. // Sets the playback position to given time (in milliseconds).
  31. function setPosition(position) {
  32. videoPlayerImpl.position = position;
  33. }
  34. function __volumeUp() {
  35. var maxVol = 1.0;
  36. var volThreshold = 0.1;
  37. if (visual.currentVolume < maxVol - volThreshold) {
  38. visual.currentVolume += volThreshold;
  39. } else {
  40. visual.currentVolume = maxVol;
  41. }
  42. }
  43. function __volumeDown() {
  44. var minVol = 0.0;
  45. var volThreshold = 0.1;
  46. if (visual.currentVolume > minVol + volThreshold) {
  47. visual.currentVolume -= volThreshold;
  48. } else {
  49. visual.currentVolume = minVol;
  50. }
  51. }
  52. function __handleStatusChange(status, playing, position, paused) {
  53. var isVisibleState = status === Video.Buffered ||
  54. status === Video.EndOfMedia;
  55. var isStalled = status === Video.Stalled;
  56. // Background
  57. if ( (isVisibleState || isStalled) && !(paused && position === 0) ) {
  58. blackBackground.opacity = 0;
  59. } else {
  60. blackBackground.opacity = 1;
  61. }
  62. // Busy indicator
  63. if (!isVisibleState && playing) {
  64. busyIndicator.opacity = 1;
  65. } else {
  66. busyIndicator.opacity = 0;
  67. }
  68. if (status === Video.EndOfMedia) {
  69. videoPlayerImpl.stop();
  70. videoPlayerImpl.position = 0;
  71. }
  72. }
  73. Rectangle {
  74. id: videoBackground
  75. color: "#000000"
  76. z: videoPlayerImpl.z - 1
  77. anchors.fill: parent
  78. }
  79. DeviceInfo {
  80. id: deviceInfo
  81. monitorCurrentProfileChanges: true
  82. onCurrentProfileChanged: {
  83. // Update volume dynamically when profile is changed.
  84. // Binding Video element volume directly to voiceRingtoneVolume
  85. // sets only initial volume but value is not updated correctly.
  86. visual.currentVolume = deviceInfo.voiceRingtoneVolume / 100;
  87. }
  88. }
  89. Video {
  90. id: videoPlayerImpl
  91. property bool playbackStarted: false
  92. volume: visual.currentVolume
  93. autoLoad: true
  94. anchors.fill: parent
  95. fillMode: Video.PreserveAspectFit
  96. focus: true
  97. MouseArea {
  98. anchors.fill: parent
  99. onClicked: {
  100. videoPlayerContainer.toggled()
  101. }
  102. }
  103. onPlayingChanged: {
  104. videoPlayerContainer.isPlaying = playing
  105. __handleStatusChange(status, isPlaying, position, paused)
  106. }
  107. onPausedChanged: {
  108. videoPlayerContainer.isPlaying = !paused
  109. __handleStatusChange(status, isPlaying, position, paused)
  110. }
  111. onStatusChanged: {
  112. if (status === Video.Buffered && !videoPlayerImpl.playbackStarted) {
  113. videoPlayerImpl.playbackStarted = true;
  114. videoPlayerContainer.playbackStarted();
  115. }
  116. __handleStatusChange(status, isPlaying, position, paused)
  117. }
  118. }
  119. Rectangle {
  120. id: blackBackground
  121. anchors.fill: parent
  122. color: "#000000"
  123. z: videoPlayerImpl.z + 1
  124. opacity: 1
  125. }
  126. BusyIndicator {
  127. id: busyIndicator
  128. anchors.centerIn: blackBackground
  129. platformStyle: BusyIndicatorStyle { size: "large" }
  130. z: blackBackground.z + 1
  131. running: true
  132. }
  133. Connections {
  134. id: volumeConnections
  135. target: volumeKeys
  136. onVolumeKeyUp: __volumeUp()
  137. onVolumeKeyDown: __volumeDown()
  138. }
  139. }