Advertisement
Guest User

Untitled

a guest
May 26th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. diff --git a/qml/pages/CameraUI.qml b/qml/pages/CameraUI.qml
  2. index 7d0381a..a0320bb 100644
  3. --- a/qml/pages/CameraUI.qml
  4. +++ b/qml/pages/CameraUI.qml
  5. @@ -120,6 +120,15 @@ Page {
  6. }
  7. }
  8.  
  9. + onRecorderStatusChanged: {
  10. + if (camera.videoRecorder.recorderStatus == CameraRecorder.FinalizingStatus) {
  11. + var path = camera.videoRecorder.outputLocation.toString()
  12. + path = path.replace(/^(file:\/{2})/,"")
  13. + console.log("finalizing: " + path)
  14. + galleryModel.append({ filePath: path })
  15. + }
  16. + }
  17. +
  18. onResolutionChanged: {
  19. console.log("Video resolution changed:", settings.resolution("video"));
  20. camera.viewfinder.resolution = getNearestViewFinderResolution();
  21. diff --git a/qml/pages/GalleryUI.qml b/qml/pages/GalleryUI.qml
  22. index 3764980..2a34dd4 100644
  23. --- a/qml/pages/GalleryUI.qml
  24. +++ b/qml/pages/GalleryUI.qml
  25. @@ -1,5 +1,7 @@
  26. import QtQuick 2.0
  27. import Sailfish.Silica 1.0
  28. +import QtMultimedia 5.6
  29. +import Nemo.Thumbnailer 1.0
  30. import uk.co.piggz.harbour_advanced_camera 1.0
  31. import "../components/"
  32.  
  33. @@ -27,6 +29,23 @@ Page {
  34. }
  35. }
  36.  
  37. + function isVideo(idx) {
  38. + if (idx < 0) return;
  39. + var fullPath = fileList.get(idx).filePath;
  40. + var fileExt = fullPath.substr(fullPath.lastIndexOf(".") + 1, 3);
  41. + console.log("Detected", fileExt, "extension...");
  42. + return (fileExt === "mp4");
  43. + }
  44. +
  45. + function getFileName(idx) {
  46. + if (idx < 0) return;
  47. + var fullPath = fileList.get(idx).filePath;
  48. + var lastSep = fullPath.lastIndexOf("/");
  49. + var fileName = fullPath.substr(lastSep + 1, fullPath.length - lastSep);
  50. + console.log("Filename:", fileName);
  51. + return fileName;
  52. + }
  53. +
  54. RoundButton {
  55. id: btnClose
  56.  
  57. @@ -94,23 +113,46 @@ Page {
  58. height: parent.height
  59. color: 'black'
  60.  
  61. - Image {
  62. + property bool isMovie: isVideo(index)
  63. + property string fileName: getFileName(index)
  64. +
  65. + Thumbnail {
  66. id: thumbnail
  67.  
  68. - asynchronous: true
  69. + width: parent.width
  70. + height: parent.height
  71. sourceSize.width: parent.width
  72. + sourceSize.height: parent.height
  73. anchors.fill: parent
  74. - fillMode: Image.PreserveAspectFit
  75. - source: "file://" + filePath
  76. + fillMode: Thumbnail.PreserveAspectFit
  77. + mimeType: isMovie ? "video/" : "image/"
  78. + //priority: Thumbnail.HighPriority
  79. + source: filePath
  80. + smooth: true
  81. +
  82. + onStatusChanged: console.log("Thumbnail status for", fileName, status)
  83.  
  84. MouseArea {
  85. anchors.fill: parent
  86. onClicked: {
  87. - console.log("Clicked", thumbnail.source);
  88. btnClose.visible = btnClose.visible ? false : true;
  89. }
  90. }
  91. }
  92. +
  93. + RoundButton {
  94. + id: btnPlay
  95. +
  96. + visible: isMovie
  97. + anchors.centerIn:parent
  98. + icon.source: "image://theme/icon-m-play"
  99. + size: Theme.itemSizeMedium
  100. +
  101. + onClicked: {
  102. + console.log("Clicked play button on", filePath);
  103. + pageStack.push(Qt.resolvedUrl("VideoPlayer.qml"), { "videoFile": filePath });
  104. + }
  105. + }
  106. }
  107. }
  108.  
  109. diff --git a/qml/pages/VideoPlayer.qml b/qml/pages/VideoPlayer.qml
  110. new file mode 100644
  111. index 0000000..27fa29f
  112. --- /dev/null
  113. +++ b/qml/pages/VideoPlayer.qml
  114. @@ -0,0 +1,53 @@
  115. +import QtQuick 2.0
  116. +import Sailfish.Silica 1.0
  117. +import QtMultimedia 5.6
  118. +
  119. +Page {
  120. + id: playerPage
  121. +
  122. + // The effective value will be restricted by ApplicationWindow.allowedOrientations
  123. + allowedOrientations: Orientation.All
  124. +
  125. + property var videoFile: ({})
  126. +
  127. + Rectangle {
  128. + width: parent.width
  129. + height: parent.height
  130. + color: "black"
  131. +
  132. + Video {
  133. + id: videoPlayer
  134. +
  135. + width: parent.width
  136. + height: parent.height
  137. + source: "file://" + videoFile
  138. + autoPlay: true
  139. + fillMode: VideoOutput.PreserveAspectFit
  140. + focus: true
  141. +
  142. + onStatusChanged: {
  143. + if (status == MediaPlayer.Loading) {
  144. + console.log("Media loading...");
  145. + } else if (status == MediaPlayer.Loaded) {
  146. + console.log("Media loaded!");
  147. + } else if (status == MediaPlayer.Buffering) {
  148. + console.log("Media buffering...");
  149. + } else if (status == MediaPlayer.Buffered) {
  150. + console.log("Media buffered!");
  151. + } else if (status == MediaPlayer.EndOfMedia) {
  152. + console.log("Media ended!");
  153. + } else if (status == MediaPlayer.InvalidMedia) {
  154. + console.log("Invalid!");
  155. + } else if (status == MediaPlayer.UnknownStatus) {
  156. + console.log("Media unknow status!");
  157. + } else {
  158. + console.log("Video player status", status);
  159. + }
  160. + }
  161. +
  162. + onPlaying: console.log("Media playing \\o/")
  163. +
  164. + onStopped: console.log("Media stopped")
  165. + }
  166. + }
  167. +}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement