Advertisement
tasuku

QML Subsonic Demo

Aug 26th, 2012
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.27 KB | None | 0 0
  1. import QtQuick 2.0
  2. import QtMultimedia 5.0
  3.  
  4. import './common/' as Common
  5. import './common/js/subsonic.js' as Subsonic
  6.  
  7. Rectangle {
  8. id: root
  9. width: 360
  10. height: 360
  11. color: 'black'
  12.  
  13. Common.ServerListModel {
  14. id: serverListModel
  15. }
  16.  
  17. Common.Ping {
  18. id: ping
  19. onPongChanged: if (pong) playlistsModel.load()
  20. }
  21.  
  22. Common.PlaylistsModel {
  23. id: playlistsModel
  24. onLoadingChanged: if (!loading && count > 0) {
  25. playlistsView.currentIndex = 0
  26. }
  27. }
  28.  
  29. Common.PlaylistModel {
  30. id: playlistModel
  31. property string playlistsId: playlistsView.currentIndex > -1 ? playlistsModel.get(playlistsView.currentIndex).id : ''
  32. onPlaylistsIdChanged: {
  33. _id = playlistsId
  34. load()
  35. }
  36. }
  37.  
  38. Row {
  39. ListView {
  40. id: playlistsView
  41. width: root.width / 3
  42. height: root.height
  43. spacing: 5
  44. model: playlistsModel
  45.  
  46. delegate: Rectangle {
  47. id: playlistsDelegate
  48. width: ListView.view.width
  49. height: 30
  50. radius: 5
  51. color: 'transparent'
  52. border.color: 'white'
  53. border.width: 1
  54. smooth: true
  55.  
  56. Text {
  57. anchors.fill: parent
  58. anchors.margins: 5
  59. verticalAlignment: Text.AlignVCenter
  60. color: 'white'
  61. text: model.name
  62. }
  63. }
  64. highlight: Rectangle {
  65. color: 'white'
  66. opacity: playlistsView.focus ? 0.50 : 0.25
  67. }
  68. focus: true
  69. Keys.onUpPressed: playlistsView.decrementCurrentIndex()
  70. Keys.onDownPressed: playlistsView.incrementCurrentIndex()
  71. Keys.onRightPressed: playlistView.focus = true
  72. Keys.onEscapePressed: Qt.quit()
  73. }
  74.  
  75. ListView {
  76. id: playlistView
  77. width: root.width / 3
  78. height: root.height
  79. spacing: 5
  80. model: playlistModel
  81. delegate: Rectangle {
  82. id: playlistDelegate
  83. width: ListView.view.width
  84. height: 30
  85. radius: 5
  86. color: 'transparent'
  87. border.color: 'white'
  88. border.width: 1
  89. smooth: true
  90.  
  91. Text {
  92. anchors.fill: parent
  93. anchors.margins: 5
  94. verticalAlignment: Text.AlignVCenter
  95. color: 'white'
  96. text: model.title
  97. }
  98. }
  99. highlight: Rectangle {
  100. color: 'white'
  101. opacity: playlistView.focus ? 0.50 : 0.25
  102. }
  103. focus: true
  104. Keys.onUpPressed: playlistView.decrementCurrentIndex()
  105. Keys.onDownPressed: playlistView.incrementCurrentIndex()
  106. Keys.onLeftPressed: playlistsView.focus = true
  107. Keys.onEscapePressed: Qt.quit()
  108. Keys.onReturnPressed: {
  109. console.debug(audio.playbackState)
  110. switch (audio.playbackState) {
  111. case Audio.PlayingState:
  112. audio.pause()
  113. break
  114. case Audio.StoppedState:
  115. audio.source = Subsonic.getStreamSongUrl(playlistModel.get(playlistView.currentIndex).id, "128", "mp3", 0)
  116. case Audio.PausedState:
  117. audio.play()
  118. break
  119. }
  120. }
  121. }
  122. }
  123.  
  124. Audio {
  125. id: audio
  126. onStatusChanged: {
  127. switch(status) {
  128. case Audio.EndOfMedia:
  129. console.debug("Audio Status: End Of Media");
  130. break;
  131. case Audio.NoMedia:
  132. console.debug("Audio Status: No Media");
  133. break;
  134. case Audio.Loading:
  135. console.debug("Audio Status: Loading");
  136. break;
  137. case Audio.Loaded:
  138. console.debug("Audio Status: Loaded");
  139. break;
  140. case Audio.Buffering:
  141. console.debug("Audio Status: Buffering");
  142. break;
  143. case Audio.Stalled:
  144. console.debug("Audio Status: Stalled");
  145. break;
  146. case Audio.Buffered:
  147. console.debug("Audio Status: Stalled");
  148. break;
  149. case Audio.InvalidMedia:
  150. console.debug("Audio Status: InvalidMedia");
  151. break;
  152. case Audio.UnknownStatus:
  153. console.debug("Audio Status: Stalled");
  154. break;
  155. default:
  156. break;
  157. }
  158. }
  159. }
  160.  
  161. Text {
  162. anchors.centerIn: parent
  163. color: 'white'
  164. text: playlistModel.loading
  165. }
  166.  
  167. MouseArea {
  168. anchors.fill: parent
  169. onClicked: {
  170. ping.ping()
  171. }
  172. }
  173.  
  174. Component.onCompleted: {
  175. Subsonic.currentServer = serverListModel.get(0)
  176. ping.ping()
  177. }
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement