Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import QtQuick 2.0
- import QtMultimedia 5.0
- import './common/' as Common
- import './common/js/subsonic.js' as Subsonic
- Rectangle {
- id: root
- width: 360
- height: 360
- color: 'black'
- property variant currentMusic: playlistView.currentIndex > -1 ? playlistModel.get(playlistView.currentIndex) : undefined
- Common.ServerListModel {
- id: serverListModel
- }
- Common.Ping {
- id: ping
- onPongChanged: if (pong) playlistsModel.load()
- }
- Common.PlaylistsModel {
- id: playlistsModel
- onLoadingChanged: if (!loading && count > 0) {
- playlistsView.currentIndex = 0
- }
- }
- Common.PlaylistModel {
- id: playlistModel
- property string playlistsId: playlistsView.currentIndex > -1 ? playlistsModel.get(playlistsView.currentIndex).id : ''
- onPlaylistsIdChanged: {
- _id = playlistsId
- load()
- }
- }
- Row {
- ListView {
- id: playlistsView
- width: root.width / 4
- height: root.height
- spacing: 5
- model: playlistsModel
- delegate: Text {
- id: playlistsDelegate
- width: ListView.view.width
- height: root.height / 15
- font.pixelSize: height / 2
- elide: Text.ElideRight
- smooth: true
- verticalAlignment: Text.AlignVCenter
- color: 'white'
- text: model.name
- }
- highlight: Item {
- Rectangle {
- anchors.left: parent.left; anchors.bottom: parent.bottom; anchors.right: parent.right
- height: 2
- color: 'white'
- opacity: playlistsView.focus ? 1.0 : 0.5
- }
- }
- focus: true
- Keys.onUpPressed: playlistsView.decrementCurrentIndex()
- Keys.onDownPressed: playlistsView.incrementCurrentIndex()
- Keys.onRightPressed: playlistView.focus = true
- Keys.onEscapePressed: Qt.quit()
- }
- ListView {
- id: playlistView
- width: root.width / 4
- height: root.height
- spacing: 5
- model: playlistModel
- delegate: Text {
- id: playlistDelegate
- width: ListView.view.width
- height: root.height / 15
- font.pixelSize: height / 2
- elide: Text.ElideRight
- smooth: true
- verticalAlignment: Text.AlignVCenter
- color: 'white'
- text: model.title
- }
- highlight: Item {
- Rectangle {
- anchors.left: parent.left; anchors.bottom: parent.bottom; anchors.right: parent.right
- height: 2
- color: 'white'
- opacity: playlistView.focus ? 1.0 : 0.5
- }
- }
- focus: true
- Keys.onUpPressed: playlistView.decrementCurrentIndex()
- Keys.onDownPressed: playlistView.incrementCurrentIndex()
- Keys.onLeftPressed: playlistsView.focus = true
- Keys.onEscapePressed: Qt.quit()
- Keys.onReturnPressed: {
- console.debug(audio.playbackState)
- switch (audio.playbackState) {
- case Audio.PlayingState:
- audio.pause()
- break
- case Audio.StoppedState:
- audio.source = Subsonic.getStreamSongUrl(playlistModel.get(playlistView.currentIndex).id, "128", "mp3", 0)
- case Audio.PausedState:
- audio.play()
- break
- }
- }
- }
- Column {
- width: root.width / 2
- spacing: 25
- Item { width: parent.width; height: 100 }
- Image {
- anchors.horizontalCenter: parent.horizontalCenter
- width: 300
- height: 300
- source: root.currentMusic ? Subsonic.getCoverArt(root.currentMusic.coverArt, 300) : ''
- }
- Text {
- anchors.horizontalCenter: parent.horizontalCenter
- text: root.currentMusic ? root.currentMusic.title : ''
- color: 'white'
- font.pixelSize: root.height / 20
- }
- Text {
- anchors.horizontalCenter: parent.horizontalCenter
- text: root.currentMusic ? root.currentMusic.artist : ''
- color: 'white'
- font.pixelSize: root.height / 30
- }
- }
- }
- Audio {
- id: audio
- onStatusChanged: {
- switch(status) {
- case Audio.EndOfMedia:
- playlistView.currentIndex = (playlistView.currentIndex + 1) % playlistView.count
- audio.source = Subsonic.getStreamSongUrl(root.currentMusic, "128", "mp3", 0)
- audio.play()
- console.debug("Audio Status: End Of Media");
- break;
- case Audio.NoMedia:
- console.debug("Audio Status: No Media");
- break;
- case Audio.Loading:
- console.debug("Audio Status: Loading");
- break;
- case Audio.Loaded:
- console.debug("Audio Status: Loaded");
- break;
- case Audio.Buffering:
- console.debug("Audio Status: Buffering");
- break;
- case Audio.Stalled:
- console.debug("Audio Status: Stalled");
- break;
- case Audio.Buffered:
- console.debug("Audio Status: Stalled");
- break;
- case Audio.InvalidMedia:
- console.debug("Audio Status: InvalidMedia");
- break;
- case Audio.UnknownStatus:
- console.debug("Audio Status: Stalled");
- break;
- default:
- break;
- }
- }
- }
- Component.onCompleted: {
- Subsonic.currentServer = serverListModel.get(0)
- ping.ping()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement