examples/QtQuick/qtvideoplayer/qml/videoplayer/main.qml

00001 import QtQuick 1.0
00002 import QtMultimediaKit 1.1
00003 import SampleFileBrowser 1.0
00004 
00005 Rectangle{
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:statusVideo
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:volumeVideo
00031         text: "Volume:" + parent.volumePos + "%"
00032         width: 150
00033         height: 50
00034         anchors.left: statusVideo.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: videoWindow
00044         source: "browse.png"
00045         anchors.top: statusVideo.bottom
00046         width: 300
00047         height:300
00048         MouseArea {
00049             anchors.fill: parent
00050             onClicked:  {
00051                 //browseFile.openDialog();
00052             }
00053         }
00054     }
00055 
00056     Rectangle{
00057         id: browseButton
00058         color: "steelblue"
00059         anchors.top: videoWindow.bottom
00060         anchors.left: parent.left
00061         height: 50
00062         width: 60
00063         Text{
00064             text: "Browse"
00065             anchors.centerIn: parent
00066         }
00067         MouseArea{
00068             anchors.fill: parent
00069             onClicked: browseFile.openDialog();
00070         }
00071     }
00072 
00073     Slider{
00074 
00075         // Position of the playing audio is shown by the position of moving slider.
00076         id:statusSlider
00077         anchors { top: browseButton.bottom; left: videoWindow.left
00078             right: videoWindow.right;
00079             //leftMargin: 20; rightMargin: 20
00080             //bottomMargin: 10
00081         }
00082     }
00083 
00084 
00085     Rectangle{
00086 
00087         // A volume icon, and a slider to control the audio volume.
00088         id:volumeContainer
00089         anchors.top: parent.width < parent.height ? statusSlider.bottom : statusMusic.bottom
00090         anchors.left: parent.width < parent.height ? parent.left : videoWindow.right
00091         height: 50
00092         width: 230
00093 
00094 
00095         Image{
00096             id:volumeIcon
00097             source: "mute.png"
00098             width: 80
00099             height:parent
00100         }
00101 
00102         Slider{
00103 
00104             // Volume slider to control the audio volume.
00105             anchors.left: volumeIcon.right
00106             y:28
00107             id:volumeSlider
00108             width:150
00109         }
00110     }
00111 
00112     // Audio player component.
00113     /*
00114     Audio { id: playMusic
00115             volume: volumeSlider.position/(volumeSlider.width - 32)
00116     }*/
00117 
00118     // Exit button, to exit the application.
00119     Image{
00120         id:exitButton
00121         anchors.right: parent.right
00122         anchors.top: parent.top
00123         source: "exit.png"
00124         MouseArea {
00125             anchors.fill: parent
00126             onPressed:  { Qt.quit() }
00127         }
00128     }
00129 
00130     // Options to play, pause and stop music.
00131     Row{
00132         id:musicOptions
00133         anchors.left: parent.width < parent.height ? parent.left : videoWindow.right
00134         anchors.bottom: parent.bottom
00135         Image{
00136             id: playOption
00137             property bool playing
00138             source: "play.png"
00139             playing:false
00140             MouseArea {
00141                 anchors.fill: parent
00142                 onClicked:  {
00143                     if(!parent.playing){
00144                         myvideo.play();
00145                         parent.source = "pause.png";
00146                         parent.playing = true;
00147                         return;
00148                     }
00149                     else{
00150                         myvideo.pause();
00151                         parent.source = "play.png";
00152                         parent.playing = false;
00153                         return;
00154                     }
00155 
00156                 }
00157             }
00158 
00159         }
00160 
00161         Image{
00162             id:stopOption
00163             source: "stop.png"
00164             MouseArea {
00165                 anchors.fill: parent
00166                 onPressed:  {
00167                     myvideo.stop();
00168                     playOption.source = "play.png";
00169                 }
00170             }
00171 
00172         }
00173     }
00174 
00175     // Connections to change the position of status slider according to the position of the audio.
00176     Connections {
00177         target: myvideo
00178         onPositionChanged: {
00179             //statusSlider.position = myvideo.position;
00180         }
00181     }
00182 
00183     // Connections to update position of the audio according to the position of the status slider.
00184     Connections {
00185         target: statusSlider
00186         onSliderMoved: {
00187             myvideo.setPosition(statusSlider.position*(playMusic.duration)/(statusSlider.width - 32));
00188         }
00189     }
00190 
00191     // Connections to change the volume icon according to the audio volume.
00192     Connections {
00193         target: volumeSlider
00194         onSliderMoved: {
00195                 myvideo.setVolume(volumeSlider.position/(volumeSlider.width - 32)*100);
00196         }
00197     }
00198 
00199     // Connections to load a new audio source file, which is selected using file browser component.
00200     Connections {
00201         target: browseFile
00202         onFileSelected: {
00203             myvideo.setMedia(newSourceFile);
00204         }
00205     }
00206 }
00207 

Generated by  doxygen 1.6.2