Advertisement
Guest User

Untitled

a guest
Jul 12th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 4.20 KB | None | 0 0
  1. import QtQuick 2.6
  2. import Sailfish.Silica 1.0
  3. import QtMultimedia 5.6
  4. import Multimedia 1.0
  5. import "../assets"
  6.  
  7. Page {
  8.     property string filePath: StandardPaths.documents + "/" + Qt.application.name + ".wav"
  9.  
  10.     AudioRecorder {
  11.         id: audioRecorder
  12.         outputLocation: filePath
  13.         onStateChanged: {
  14.             if (state === AudioRecorder.StoppedState) {
  15.                 audioPlayer.source = "";
  16.                 audioPlayer.source = filePath;
  17.             }
  18.         }
  19.     }
  20.     Audio {
  21.         id: audioPlayer
  22.         source: filePath
  23.         autoLoad: true
  24.     }
  25.     Column {
  26.         anchors.fill: parent
  27.         spacing: Theme.paddingLarge
  28.  
  29.         PageHeader { title: qsTr("Dictaphone") }
  30.         ValueDisplay {
  31.             id: recordInfo
  32.             label: qsTr("Recorded duration")
  33.             value: qsTr("%1 s").arg((audioRecorder.duration || audioPlayer.duration) / 1000)
  34.             width: parent.width
  35.         }
  36.         Slider {
  37.             id: playInfo
  38.             label: qsTr("Player position")
  39.             width: parent.width
  40.             minimumValue: 0
  41.             maximumValue: audioPlayer.duration || 1
  42.             value: audioPlayer.position
  43.             valueText: qsTr("%1 s").arg(value / 1000)
  44.             enabled: false
  45.             down: true
  46.             handleVisible: false
  47.         }
  48.     }
  49.     Row {
  50.         id: buttonsRow
  51.         anchors {
  52.             horizontalCenter: parent.horizontalCenter
  53.             bottom: parent.bottom
  54.             bottomMargin: Theme.paddingLarge
  55.         }
  56.         spacing: Theme.paddingLarge
  57.  
  58.         IconButton {
  59.             id: recordStartButton
  60.             icon.source: "image://theme/icon-m-call-recording-on"
  61.             onClicked: audioRecorder.record()
  62.         }
  63.         IconButton {
  64.             id: recordPauseButton
  65.             icon.source: "image://theme/icon-m-pause"
  66.             visible: false
  67.             onClicked: audioRecorder.pause()
  68.         }
  69.         IconButton {
  70.             id: recordStopButton
  71.             icon.source: "image://theme/icon-m-call-recording-off"
  72.             visible: false
  73.             onClicked: audioRecorder.stop()
  74.         }
  75.         IconButton {
  76.             id: playStartButton
  77.             icon.source: "image://theme/icon-m-play"
  78.             onClicked: audioPlayer.play()
  79.         }
  80.         IconButton {
  81.             id: playPauseButton
  82.             icon.source: "image://theme/icon-m-pause"
  83.             visible: false
  84.             onClicked: audioPlayer.pause()
  85.         }
  86.         IconButton {
  87.             id: playStopButton
  88.             icon.source: "image://theme/icon-m-clear"
  89.             visible: false
  90.             onClicked: audioPlayer.stop()
  91.         }
  92.  
  93.         states: [
  94.             State {
  95.                 when: audioRecorder.state === AudioRecorder.RecordingState
  96.  
  97.                 PropertyChanges { target: recordStartButton; visible: false }
  98.                 PropertyChanges { target: recordPauseButton; visible: true }
  99.                 PropertyChanges { target: recordStopButton; visible: true }
  100.                 PropertyChanges { target: playStartButton; visible: false }
  101.             },
  102.             State {
  103.                 when: audioRecorder.state === AudioRecorder.PausedState
  104.  
  105.                 PropertyChanges { target: recordStopButton; visible: true }
  106.                 PropertyChanges { target: playStartButton; visible: false }
  107.             },
  108.             State {
  109.                 when: audioPlayer.playbackState === Audio.PlayingState
  110.  
  111.                 PropertyChanges { target: recordStartButton; visible: false }
  112.                 PropertyChanges { target: playStartButton; visible: false }
  113.                 PropertyChanges { target: playPauseButton; visible: true }
  114.                 PropertyChanges { target: playStopButton; visible: true }
  115.                 PropertyChanges { target: playInfo; down: false }
  116.             },
  117.             State {
  118.                 when: audioPlayer.playbackState === Audio.PausedState
  119.  
  120.                 PropertyChanges { target: recordStartButton; visible: false }
  121.                 PropertyChanges { target: playStopButton; visible: true }
  122.                 PropertyChanges { target: playInfo; down: false }
  123.             }
  124.         ]
  125.     }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement