Created
October 24, 2016 13:52
-
-
Save NetBUG/7a0f1697bae4343bad2c70d83b40ffe1 to your computer and use it in GitHub Desktop.
raw /usr/share/jolla-mediaplayer/mediaplayer.qml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -*- qml -*- | |
import QtQuick 2.0 | |
import Sailfish.Silica 1.0 | |
import Sailfish.Media 1.0 | |
import com.jolla.mediaplayer 1.0 | |
import org.nemomobile.thumbnailer 1.0 | |
import org.nemomobile.dbus 2.0 | |
import "scripts/AlbumArtFinder.js" as AlbumArtFinder | |
import "cover" | |
import "pages" | |
ApplicationWindow { | |
id: root | |
property alias dockedPanel: panel | |
property alias playlists: playlistManager | |
property alias visualAudioAppModel: audioAppModel | |
property Item activeMediaSource | |
property Component coverOverride: (activeMediaSource && activeMediaSource.hasOwnProperty("cover")) | |
? activeMediaSource.cover | |
: null | |
property bool mediaKeyOverride: activeMediaSource | |
&& activeMediaSource.hasOwnProperty("overrideMediaKeys") | |
&& activeMediaSource.overrideMediaKeys | |
allowedOrientations: Screen.sizeCategory > Screen.Medium | |
? defaultAllowedOrientations | |
: defaultAllowedOrientations & Orientation.PortraitMask | |
_defaultPageOrientations: Orientation.All | |
_defaultLabelFormat: Text.PlainText | |
cover: coverOverride != null ? coverOverride : mediaPlayerCover | |
bottomMargin: panel.visibleSize | |
initialPage: Component { | |
MainViewPage { | |
onMediaSourceActivated: { | |
root.activeMediaSource = source | |
} | |
} | |
} | |
function fetchAlbumArts(count) { | |
var artList = [] | |
for (var i = 0; i < count; ++i) { | |
var albumArt = AlbumArtFinder.randomArt(allSongModel, albumArtProvider) | |
artList.push(albumArt) | |
} | |
return artList | |
} | |
MediaPlayerCover { | |
id: mediaPlayerCover | |
enableActions: coverOverride === null | |
} | |
VisualAudioAppModel { | |
id: audioAppModel | |
modelActive: root.applicationActive | |
} | |
GriloTrackerModel { | |
id: allSongModel | |
query: { | |
//: placeholder string for albums without a known name | |
//% "Unknown album" | |
var unknownAlbum = qsTrId("mediaplayer-la-unknown-album") | |
//: placeholder string to be shown for media without a known artist | |
//% "Unknown artist" | |
var unknownArtist = qsTrId("mediaplayer-la-unknown-artist") | |
return AudioTrackerHelpers.getSongsQuery("", {"unknownArtist": unknownArtist, "unknownAlbum": unknownAlbum}) | |
} | |
onFinished: { | |
var artList = fetchAlbumArts(3) | |
if (artList[0]) { | |
if (!artList[0].url || artList[0].url == "") { | |
mediaPlayerCover.idleArtist = artList[0].author ? artList[0].author : "" | |
mediaPlayerCover.idleSong = artList[0].title ? artList[0].title : "" | |
} else { | |
mediaPlayerCover.idle.largeAlbumArt = artList[0].url | |
mediaPlayerCover.idle.leftSmallAlbumArt = artList[1] && artList[1].url ? artList[1].url : "" | |
mediaPlayerCover.idle.rightSmallAlbumArt = artList[2] && artList[2].url ? artList[2].url : "" | |
mediaPlayerCover.idle.sourcesReady = true | |
} | |
} | |
} | |
} | |
MediaKeys { | |
id: mediaKeys | |
active: AudioPlayer.active && !root.mediaKeyOverride | |
} | |
MediaPlayerDockedPanel { | |
id: panel | |
z: 1 | |
author: visualAudioAppModel.metadata && 'artist' in visualAudioAppModel.metadata ? visualAudioAppModel.metadata.artist : "" | |
title: visualAudioAppModel.metadata && 'title' in visualAudioAppModel.metadata ? visualAudioAppModel.metadata.title : "" | |
duration: visualAudioAppModel.duration / 1000 | |
state: visualAudioAppModel.state | |
active: visualAudioAppModel.active | |
position: visualAudioAppModel.position / 1000 | |
} | |
AlbumArtProvider { | |
id: albumArtProvider | |
} | |
PlaylistManager { | |
id: playlistManager | |
} | |
CoverActionList { | |
id: idleActions | |
enabled: !AudioPlayer.active && allSongModel.count > 0 && coverOverride === null | |
CoverAction { | |
iconSource: "image://theme/icon-cover-shuffle" | |
onTriggered: AudioPlayer.shuffleAndPlay(allSongModel, allSongModel.count) | |
} | |
} | |
Component { | |
id: playQueuePage | |
PlayQueuePage {} | |
} | |
DBusAdaptor { | |
service: "com.jolla.mediaplayer" | |
path: "/com/jolla/mediaplayer/ui" | |
iface: "com.jolla.mediaplayer.ui" | |
function activateWindow(arg) { | |
root.activate() | |
} | |
function openUrl(arg) { | |
if (arg[0] == undefined) { | |
return false | |
} | |
AudioPlayer.playUrl(Qt.resolvedUrl(arg[0])) | |
if (!pageStack.currentPage || pageStack.currentPage.objectName !== "PlayQueuePage") { | |
root.pageStack.push(playQueuePage, {}, PageStackAction.Immediate) | |
} | |
activate() | |
return true | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment