Advertisement
tasuku

Subsonic client for RPi

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