git.iko.soy/maciek134/podphoenix
on main help sign in
* Fix position saving and restoring on the episodes page
7cba1b3Michael Sheldon
app/podbird.qml+28−15
@@ -221,6 +221,21 @@ MainView {
221 }
221 }
222 }
222 }
223
223
224+ // This reduces incidences of media-hub getting confused and
225+ // continuing to play the previous file when clearing a playlist
226+ // and starting a new episode
227+ Timer {
228+ id: playStarter
229+ interval: 500
230+ onTriggered: {
231+ // Ideally we'd check the buffer progress here and base it on that
232+ // but media-hub doesn't report it correctly
233+ console.log("Starting playback")
234+ player.play()
235+ player.restorePosition()
236+ }
237+ }
238+
224 MediaPlayer {
239 MediaPlayer {
225 id: player
240 id: player
226
241
@@ -275,6 +290,14 @@ MainView {
275 }
290 }
276 }
291 }
277
292
293+ function restorePosition() {
294+ if (playbackState === MediaPlayer.PlayingState && pendingSeek !== 0) {
295+ player.seek(pendingSeek)
296+ player.clearPosition()
297+ pendingSeek = 0;
298+ }
299+ }
300+
278 function clearPosition() {
301 function clearPosition() {
279 if (currentGuid) {
302 if (currentGuid) {
280 var db = Podcasts.init()
303 var db = Podcasts.init()
@@ -285,6 +308,8 @@ MainView {
285 }
308 }
286
309
287 function playEpisode(guid, image, name, artist, url, position) {
310 function playEpisode(guid, image, name, artist, url, position) {
311+ player.pause()
312+
288 // Clear current queue
313 // Clear current queue
289 player.playlist.clear()
314 player.playlist.clear()
290 Podcasts.clearQueue()
315 Podcasts.clearQueue()
@@ -295,7 +320,7 @@ MainView {
295
320
296 // Play episode
321 // Play episode
297 pendingSeek = position
322 pendingSeek = position
298− player.play()
323+ playStarter.restart()
299 }
324 }
300
325
301 function addEpisodeToQueue(guid, image, name, artist, url, position) {
326 function addEpisodeToQueue(guid, image, name, artist, url, position) {
@@ -337,23 +362,11 @@ MainView {
337 }
362 }
338
363
339 onPlaybackStateChanged: {
364 onPlaybackStateChanged: {
340− if (playbackState === MediaPlayer.PlayingState && pendingSeek !== 0) {
365+ restorePosition()
341− player.seek(pendingSeek)
342− player.clearPosition()
343− pendingSeek = 0;
344− }
345 }
366 }
346
367
347 onStatusChanged: {
368 onStatusChanged: {
348− if (status === MediaPlayer.Loading) {
369+ if (status === MediaPlayer.EndOfMedia) {
349− if (playbackState === MediaPlayer.PlayingState && pendingSeek !== 0) {
350− player.seek(pendingSeek)
351− player.clearPosition()
352− pendingSeek = 0;
353− } else {
354− play()
355− }
356− } else if (status === MediaPlayer.EndOfMedia) {
357 console.log("[LOG]: End of Media. Stopping.")
370 console.log("[LOG]: End of Media. Stopping.")
358 endOfMedia = true
371 endOfMedia = true
359 stop()
372 stop()
app/podcasts.js+8−11
@@ -117,17 +117,14 @@ function lookup(source) {
117 }
117 }
118
118
119 db.transaction(function(tx) {
119 db.transaction(function(tx) {
120− var rs = tx.executeSql("SELECT * FROM Queue ORDER BY ind ASC");
120+ var rs = tx.executeSql("SELECT * FROM Queue WHERE url = ?", [source]);
121− for(var i = 0; i < rs.rows.length; i++) {
121+ if (rs.rows.length > 0) {
122− var episode = rs.rows.item(i);
122+ var episode = rs.rows.item(0);
123− if (source === episode.url) {
124− meta.name = episode.name
123+ meta.name = episode.name
125− meta.artist = episode.artist
124+ meta.artist = episode.artist
126− meta.image = episode.image
125+ meta.image = episode.image
127− meta.guid = episode.guid
126+ meta.guid = episode.guid
128− meta.position = episode.position
127+ meta.position = episode.position
129− break
130− }
131 }
128 }
132 });
129 });
133
130
app/ui/EpisodesPage.qml+12−2
@@ -682,8 +682,18 @@ Page {
682 selected = !selected
682 selected = !selected
683 } else {
683 } else {
684 if (currentGuid !== model.guid) {
684 if (currentGuid !== model.guid) {
685+ player.savePosition()
685− currentUrl = model.downloadedfile ? "file://" + model.downloadedfile : model.audiourl;
686+ currentUrl = model.downloadedfile ? "file://" + model.downloadedfile : model.audiourl
687+ // We need to refetch the episode position as it may have changed without the model refreshing
688+ var db = Podcasts.init()
689+ db.transaction(function (tx) {
690+ var position = 0
691+ var rs = tx.executeSql("SELECT position FROM Episode WHERE guid=? AND position > 0", [model.guid])
692+ if (rs.rows.length > 0) {
693+ position = rs.rows.item(0).position
694+ }
686− player.playEpisode(model.guid, model.image, model.name, model.artist, currentUrl)
695+ player.playEpisode(model.guid, model.image, model.name, model.artist, currentUrl, position)
696+ });
687 }
697 }
688 }
698 }
689 }
699 }
app/ui/EpisodesTab.qml+10−1
@@ -671,7 +671,16 @@ Tab {
671 if (currentGuid !== model.guid) {
671 if (currentGuid !== model.guid) {
672 player.savePosition()
672 player.savePosition()
673 currentUrl = model.downloadedfile ? "file://" + model.downloadedfile : model.audiourl
673 currentUrl = model.downloadedfile ? "file://" + model.downloadedfile : model.audiourl
674+ // We need to refetch the episode position as it may have changed without the model refreshing
675+ var db = Podcasts.init()
676+ db.transaction(function (tx) {
677+ var position = 0
678+ var rs = tx.executeSql("SELECT position FROM Episode WHERE guid=? AND position > 0", [model.guid])
679+ if (rs.rows.length > 0) {
680+ position = rs.rows.item(0).position
681+ }
674− player.playEpisode(model.guid, model.image, model.name, model.artist, currentUrl, model.position)
682+ player.playEpisode(model.guid, model.image, model.name, model.artist, currentUrl, position)
683+ });
675 }
684 }
676 }
685 }
677 }
686 }