Commit 7fd2f52d authored by kempe's avatar kempe

Fixed player controls

* Pause now stops audio (Still pause icon but 
sailfish has no stop icon so…)
* Removed some unnecessary action on*Changed
* Fixed logic in play next/prev favourite
* Moved out playPrev to match playNext
* Fixed coverage actions
parent 2af30c8f
......@@ -11,11 +11,39 @@ DockedPanel {
property var stationData: null;
property bool isFavorite: false
function pause() {
audio.pause()
function play(station) {
if(!player.expanded)
player.open = true;
player.stationData = JSON.parse(JSON.stringify(station));
player.isFavorite = FavoritesUtils.isFavorite(stationData)
window.stationIcon = stationData.stationLogo;
stop()
audio.source = stationData.url;
audio.play()
}
function playNext() {
var nextStation = FavoritesUtils.getNextFavorite(stationData)
console.debug("Playing next favorite", JSON.stringify(nextStation))
play(nextStation)
}
function playPrev() {
var prevStation = FavoritesUtils.getPrevFavorite(stationData)
console.debug("Playing prev favorite", JSON.stringify(prevStation))
play(prevStation)
}
function stop() {
audio.stopAndReset()
}
function resume() {
audio.source = stationData.url;
audio.play()
}
......@@ -23,12 +51,6 @@ DockedPanel {
return audio.isPlaying()
}
function playNext() {
var nextStation = FavoritesUtils.getNextFavorite(stationData)
console.log("Playing next favorite", nextStation)
play(nextStation)
}
width: parent.width
height: Theme.itemSizeExtraLarge + Theme.paddingLarge
dock: Dock.Bottom
......@@ -44,7 +66,6 @@ DockedPanel {
}
onSleepTriggered: {
if(isPlaying()) {
audio.stop()
stop();
}
}
......@@ -74,8 +95,8 @@ DockedPanel {
text: qsTr("Set")
onClicked: {
var sTime = DB.loadSleepTimer()
console.log("DB HOUR: " + sTime.hour)
console.log("DB MINUTE: " + sTime.minute)
console.debug("DB HOUR: " + sTime.hour)
console.debug("DB MINUTE: " + sTime.minute)
var dialog = pageStack.push("Sailfish.Silica.TimePickerDialog", {
hour: sTime.hour,
minute: sTime.minute,
......@@ -96,7 +117,7 @@ DockedPanel {
MouseArea {
id: opener
anchors.fill: parent
onClicked: console.log("Show fullscreen player controls")
onClicked: console.debug("Show fullscreen player controls")
}
Row {
......@@ -157,20 +178,13 @@ DockedPanel {
icon.source: isFavorite ? "image://theme/icon-m-favorite-selected" : "image://theme/icon-m-favorite"
onClicked: {
if(!isFavorite) {
var station = {
name: player.stationData.name,
stationIcon: player.stationData.stationLogo,
country: player.stationData.country,
genre: player.stationData.genre,
url: player.stationData.url
}
FavoritesUtils.addFavorite(station)
FavoritesUtils.addFavorite(stationData)
isFavorite = FavoritesUtils.isFavorite(stationData)
}
else {
FavoritesUtils.removeFavorite(stationData)
isFavorite = FavoritesUtils.isFavorite(stationData)
}
isFavorite = FavoritesUtils.isFavorite(stationData)
}
}
......@@ -179,9 +193,7 @@ DockedPanel {
anchors.verticalCenter: parent.verticalCenter
icon.source: "image://theme/icon-m-previous-song"
onClicked: {
var prevStation = FavoritesUtils.getPrevFavorite(stationData)
console.log("Playing prev favorite", prevStation)
radioAPI.playStationById(prevStation.id);
playPrev()
}
}
......@@ -189,7 +201,7 @@ DockedPanel {
width: controls.itemWidth
anchors.verticalCenter: parent.verticalCenter
icon.source: audio.isPlaying() ? "image://theme/icon-m-pause" : "image://theme/icon-m-play"
onClicked: audio.isPlaying() ? audio.pause() : audio.play()
onClicked: audio.isPlaying() ? stop() : resume()
}
IconButton {
......@@ -205,24 +217,27 @@ DockedPanel {
}
}
function play(station) {
if(!player.expanded)
player.open = true;
player.stationData = station;
window.stationIcon = stationData.stationLogo;
audio.source = stationData.url;
player.isFavorite = FavoritesUtils.isFavorite(stationData)
}
Audio {
id: audio
autoLoad: false
autoPlay: false
function isPlaying() {
return playbackState == Audio.PlayingState
}
function isLoading() {
return isPlaying() && bufferProgress < 1
}
function stopAndReset() {
audio.stop()
audio.source = "";
}
onError: {
console.log("AudioPlayer: onError: ", error)
console.debug("AudioPlayer: onError: ", error)
var errorMessage = "";
switch (error) {
......@@ -254,73 +269,19 @@ DockedPanel {
break;
}
console.log(errorMessage)
console.debug(errorMessage)
}
onStatusChanged: {
console.log("AudioPlayer: Status changed: ", audio.state)
switch(audio.state) {
case Audio.NoMedia:
audio.stop()
console.log("Status: NoMedia")
break;
case Audio.Loading:
audio.stop()
console.log("Status: Loading")
break;
case Audio.Loaded:
console.log("Status: Loaded")
break;
case Audio.Buffering:
console.log("Status: Buffering")
break;
case Audio.Stalled:
console.log("Status: Stalled")
break;
case Audio.Buffered:
console.log("Status: Buffered")
break;
case Audio.EndOfMedia:
console.log("Status: EndOfMedia")
break;
case Audio.InvalidMedia:
console.log("Status: InvalidMedia")
break;
case Audio.UnknownStatus:
console.log("Status: UnknownStatus")
break;
}
console.debug("AudioPlayer: Status changed: ", status)
}
onSourceChanged: {
switch(playbackState) {
case Audio.PlayingState:
stop()
console.log("AudioPlayer: Playing")
break;
case Audio.PausedState:
stop()
console.log("AudioPlayer: Paused")
break;
case Audio.StoppedState:
console.log("AudioPlayer: Stopped")
break;
}
play();
console.debug("New source: ", source)
}
onPlaybackStateChanged: {
console.log("AudioPlayer PlaybackState changed: ", playbackState)
}
function isPlaying() {
return audio.playbackState == Audio.PlayingState
}
function isLoading() {
return status === Audio.Buffering || status === Audio.Stalled || status === Audio.Loading
console.debug("AudioPlayer PlaybackState changed: ", playbackState)
}
}
}
......@@ -36,10 +36,13 @@ function getNextFavorite(currentStation) {
return favoritesModel.get(0);
var currentIndex = getModelIndexFromStation(currentStation);
if(currentIndex+1 >= favoritesModel.count)
console.debug("Get next station. Current index:", JSON.stringify(currentIndex))
var nextIndex = currentIndex+1
if(nextIndex >= favoritesModel.count)
return favoritesModel.get(0);
return favoritesModel.get(currentIndex+1);
return favoritesModel.get(nextIndex);
}
function getPrevFavorite(currentStation) {
......@@ -48,10 +51,12 @@ function getPrevFavorite(currentStation) {
var currentIndex = getModelIndexFromStation(currentStation);
console.log("currentIndex", currentIndex)
if(currentIndex-1 < 0)
var prevIndex = currentIndex-1
if(prevIndex < 0)
return favoritesModel.get(favoritesModel.count-1);
return favoritesModel.get(currentIndex-1);
return favoritesModel.get(prevIndex);
}
function isFavorite(station) {
......
......@@ -24,11 +24,12 @@ CoverBackground {
CoverAction {
iconSource: player.isPlaying() ? "image://theme/icon-cover-pause" : "image://theme/icon-cover-play"
onTriggered: {
if(player.isPlaying())
player.pause()
else
if(!player.stationData)
player.playNext()
if(!player.isPlaying())
player.resume()
else
player.stop()
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment