examples/QtQuick/qmlaudioplayer/qml/qmlaudioplayer/main.qml

00001 import QtQuick 1.0
00002 import QtMultimediaKit 1.1
00003 import SampleFileBrowser 1.0
00004 
00005 ApplicationWindow{
00006     id:main
00007 
00008     // Variables to find the current status and volume of the audio.
00009     property int statusPos
00010     property int volumePos
00011     width: 360
00012     height: 640
00013     statusPos: (playMusic.duration - playMusic.position)/1000
00014     volumePos: (playMusic.volume)*100
00015 
00016     Text{
00017 
00018         // Display the remaining duration of the audio loaded in seconds.
00019         id:statusMusic
00020         text: "Duration:"+ parent.statusPos + "sec"
00021         width: 150
00022         height: 50
00023         elide: Text.ElideRight
00024         wrapMode: Text.WrapAnywhere
00025     }
00026 
00027     Text{
00028 
00029         // Display the volume level of the music.
00030         id:volumeMusic
00031         text: "Volume:" + parent.volumePos + "%"
00032         width: 150
00033         height: 50
00034         anchors.left: statusMusic.right
00035     }
00036 
00037     // File browser component to load the supported audio files.
00038     MyFileBrowser{id:browseFile}
00039 
00040     Image{
00041 
00042         // Browse icon, which open the file dialog when clicked.
00043         id:browse
00044         source: "browse.png"
00045         anchors.top: statusMusic.bottom
00046         width: 300
00047         height:300
00048         MouseArea {
00049             anchors.fill: parent
00050             onClicked:  {
00051                 browseFile.openDialog();
00052             }
00053         }
00054     }
00055 
00056     Slider{
00057 
00058         // Position of the playing audio is shown by the position of moving slider.
00059         id:statusSlider
00060         anchors { bottom: browse.bottom; left: browse.left
00061             right: browse.right;
00062             //leftMargin: 20; rightMargin: 20
00063             //bottomMargin: 10
00064         }
00065     }
00066 
00067 
00068     Rectangle{
00069 
00070         // A volume icon, and a slider to control the audio volume.
00071         id:volumeContainer
00072         anchors.top: parent.width < parent.height ? statusSlider.bottom : statusMusic.bottom
00073         anchors.left: parent.width < parent.height ? parent.left : browse.right
00074         height: 50
00075         width: 230
00076 
00077 
00078         Image{
00079             id:volumeIcon
00080             source: "mute.png"
00081             width: 80
00082             height:parent
00083         }
00084 
00085         Slider{
00086 
00087             // Volume slider to control the audio volume.
00088             anchors.left: volumeIcon.right
00089             y:28
00090             id:volumeSlider
00091             width:150
00092         }
00093     }
00094 
00095     // Audio player component.
00096     Audio { id: playMusic; source: "music.wav";
00097             volume: volumeSlider.position/(volumeSlider.width - 32)
00098     }
00099 
00100     // Exit button, to exit the application.
00101     Image{
00102         id:exitButton
00103         anchors.right: parent.right
00104         anchors.top: parent.top
00105         source: "exit.png"
00106         MouseArea {
00107             anchors.fill: parent
00108             onPressed:  { Qt.quit() }
00109         }
00110     }
00111 
00112     // Options to play, pause and stop music.
00113     Row{
00114         id:musicOptions
00115         anchors.left: parent.width < parent.height ? parent.left : browse.right
00116         anchors.bottom: parent.bottom
00117         Image{
00118             id: playOption
00119             property bool playing
00120             source: "play.png"
00121             playing:false
00122             MouseArea {
00123                 anchors.fill: parent
00124                 onClicked:  {
00125                     if(!parent.playing){
00126                         playMusic.play();
00127                         parent.source = "pause.png";
00128                         parent.playing = true;
00129                         return;
00130                     }
00131                     else{
00132                         playMusic.pause();
00133                         parent.source = "play.png";
00134                         parent.playing = false;
00135                         return;
00136                     }
00137 
00138                 }
00139             }
00140 
00141         }
00142 
00143         Image{
00144             id:stopOption
00145             source: "stop.png"
00146             MouseArea {
00147                 anchors.fill: parent
00148                 onPressed:  {
00149                     playMusic.stop();
00150                     playOption.source = "play.png";
00151                 }
00152             }
00153 
00154         }
00155     }
00156 
00157     // Connections to change the position of status slider according to the position of the audio.
00158     Connections {
00159         target: playMusic
00160         onPositionChanged: {
00161             statusSlider.position = playMusic.position * (statusSlider.width -32)/playMusic.duration;
00162         }
00163     }
00164 
00165     // Connections to update position of the audio according to the position of the status slider.
00166     Connections {
00167         target: statusSlider
00168         onSliderMoved: {
00169             playMusic.position = statusSlider.position*(playMusic.duration)/(statusSlider.width - 32);
00170         }
00171     }
00172 
00173     // Connections to change the volume icon according to the audio volume.
00174     Connections {
00175         target: volumeSlider
00176         onSliderMoved: {
00177             if(main.volumePos == 0)
00178                 volumeIcon.source = "mute.png"
00179             else
00180                 volumeIcon.source = "volume.png"
00181         }
00182     }
00183 
00184     // Connections to load a new audio source file, which is selected using file browser component.
00185     Connections {
00186         target: browseFile
00187         onFileSelected: {
00188             playMusic.source = newSourceFile;
00189         }
00190     }
00191 }
00192 

Generated by  doxygen 1.6.2