git.iko.soy/maciek134/podphoenix
on main help sign in
Implemented restoring queue, resuming of episode where stopped and fixed some playback issues
commit401dff9c475ff09b5cd0c49164b2911e71b24f9e authorDaniel Kutka <dano.kutka@gmail.com> dateWed 8 Jul 2020, 21:32 (6 years ago) parent31b6106
6 files changed+85−38
app/podbird.qml+32−26 app/podcasts.js+4 app/ui/EpisodesPage.qml+2−2 app/ui/EpisodesTab.qml+5−5 app/ui/FullPlayingView.qml+28−5 app/ui/SettingsPage.qml+14
app/podbird.qml+32−26
@@ -42,13 +42,6 @@ MainView {
4242 theme.name: settings.themeName == "Dark.qml" ? "Ubuntu.Components.Themes.SuruDark"
4343 : "Ubuntu.Components.Themes.Ambiance"
4444
45− Component.onDestruction: {
46− var db = Podcasts.init()
47− db.transaction(function (tx) {
48− tx.executeSql('UPDATE Episode SET queued=0 WHERE queued=1');
49− })
50− Podcasts.clearQueue()
51− }
5245
5346 // RefreshModel function to call refreshModel() function of the tab currently
5447 // visible on application start.
@@ -62,9 +55,6 @@ MainView {
6255
6356 Component.onCompleted: {
6457 var db = Podcasts.init()
65− db.transaction(function (tx) {
66− tx.executeSql('UPDATE Episode SET queued=0 WHERE queued=1');
67− })
6858
6959 var today = new Date()
7060 // Only automatically check for podcasts on launch once every 12 hours
@@ -126,6 +116,8 @@ MainView {
126116 property bool showListView: true
127117 property int skipForward: 30
128118 property int skipBack: 10
119+ property bool continueWhereStopped: true
120+ property int playlistIndex: -1
129121 property bool downloadOverWifiOnly: true
130122 }
131123
@@ -232,14 +224,15 @@ MainView {
232224 // but media-hub doesn't report it correctly
233225 console.log("Starting playback")
234226 player.play()
235− player.restorePosition()
236227 }
237228 }
238229
239230 MediaPlayer {
240231 id: player
241232
242− onPositionChanged: console.log("DEBUG: player position changed to: ", position)
233+ onPositionChanged: {
234+ restorePosition()
235+ }
243236
244237 // Wrapper function around decodeURIComponent() to prevent exceptions
245238 // from bubbling up to the app.
@@ -277,26 +270,42 @@ MainView {
277270 savePosition()
278271 } else {
279272 play()
280− // Clear the last saved position when we start playing again
281− clearPosition()
282273 }
283274 }
284275
285276 function savePosition() {
277+ podbird.settings.playlistIndex = playlist.currentIndex
286278 if (currentGuid) {
287279 var db = Podcasts.init()
288280 db.transaction(function (tx) {
289281 tx.executeSql("UPDATE Episode SET position=? WHERE guid=?", [player.position, currentGuid])
290282 tx.executeSql("UPDATE Queue SET position=? WHERE guid=?", [player.position, currentGuid])
283+ //if(player.position / player.duration > 0.90)
284+ // tx.executeSql("UPDATE Episode SET listened=1 WHERE guid=?", [currentGuid])
291285 })
292286 }
293287 }
294288
289+ function restoreFromQueue() {
290+ var db = Podcasts.init()
291+ db.transaction(function (tx) {
292+ var rs = tx.executeSql("SELECT * FROM Queue")
293+ for (var i=0; i<rs.rows.length;i++) {
294+ var episode = rs.rows.item(i)
295+ console.log(episode.name)
296+ player.playlist.addItem(episode.url)
297+ }
298+ })
299+ if(playlist.itemCount > podbird.settings.playlistIndex)
300+ playlist.currentIndex = podbird.settings.playlistIndex
301+ }
302+
295303 function restorePosition() {
296− if (playbackState === MediaPlayer.PlayingState && pendingSeek !== 0) {
297− player.seek(pendingSeek)
298− player.clearPosition()
299− pendingSeek = 0;
304+ if(playbackState === MediaPlayer.PlayingState && status === MediaPlayer.Loaded && pendingSeek){
305+ //ugly hack because seek function does not seems to work async
306+ var p = pendingSeek
307+ pendingSeek = 0
308+ player.seek(p)
300309 }
301310 }
302311
@@ -345,7 +354,6 @@ MainView {
345354 }
346355
347356 property bool endOfMedia: false
348− property double progress: 0
349357 property int pendingSeek: 0
350358
351359 playlist: Playlist {
@@ -361,16 +369,10 @@ MainView {
361369 currentArtist = meta.artist
362370 currentImage = meta.image
363371 currentGuid = meta.guid
364− player.pendingSeek = meta.position
365− console.log("DEBUG: player.pendingSeek: ", player.pendingSeek, " meta.position ", meta.position)
372+ player.pendingSeek = podbird.settings.continueWhereStopped && meta.position > 5000 ? meta.position : 0
366373 }
367374 }
368375
369− onPlaybackStateChanged: {
370− console.log("DEBUG: Restoring Position to: ", player.position)
371− restorePosition()
372− }
373−
374376 onStatusChanged: {
375377 if (status === MediaPlayer.EndOfMedia) {
376378 console.log("[LOG]: End of Media. Stopping.")
@@ -399,6 +401,10 @@ MainView {
399401 Component.onDestruction: {
400402 savePosition()
401403 }
404+
405+ Component.onCompleted: {
406+ restoreFromQueue()
407+ }
402408 }
403409
404410 PageStack {
app/podcasts.js+4
@@ -104,6 +104,10 @@ function clearQueue() {
104104 db.transaction(function(tx) {
105105 tx.executeSql("DELETE FROM Queue");
106106 });
107+
108+ db.transaction(function (tx) {
109+ tx.executeSql('UPDATE Episode SET queued=0 WHERE queued=1');
110+ });
107111}
108112
109113function lookup(source) {
app/ui/EpisodesPage.qml+2−2
@@ -574,8 +574,8 @@ Page {
574574
575575 subtitle.text: model.duration === 0 || model.duration === undefined ? model.downloadedfile ? "📎 " + Qt.formatDate(new Date(model.published), "MMM d, yyyy")
576576 : Qt.formatDate(new Date(model.published), "MMM d, yyyy")
577− : model.downloadedfile ? "📎 " + Podcasts.formatEpisodeTime(model.duration) + " | " + Qt.formatDate(new Date(model.published), "MMM d, yyyy")
578− : Podcasts.formatEpisodeTime(model.duration) + " | " + Qt.formatDate(new Date(model.published), "MMM d, yyyy")
577+ : model.downloadedfile ? "📎 " + Podcasts.formatEpisodeTime(model.position/1000) + "/" + Podcasts.formatEpisodeTime(model.duration) + " | " + Qt.formatDate(new Date(model.published), "MMM d, yyyy")
578+ : Podcasts.formatEpisodeTime(model.position/1000) + "/" + Podcasts.formatEpisodeTime(model.duration) + " | " + Qt.formatDate(new Date(model.published), "MMM d, yyyy")
579579 subtitle.color: podbird.appTheme.baseSubText
580580
581581 padding.top: units.gu(1)
app/ui/EpisodesTab.qml+5−5
@@ -544,8 +544,8 @@ Tab {
544544
545545 subtitle.text: model.duration === 0 || model.duration === undefined ? model.downloadedfile ? "📎 " + model.artist
546546 : model.artist
547− : model.downloadedfile ? "📎 " + Podcasts.formatEpisodeTime(model.duration) + " | " + model.artist
548− : Podcasts.formatEpisodeTime(model.duration) + " | " + model.artist
547+ : model.downloadedfile ? "📎 " + Podcasts.formatEpisodeTime(model.position/1000) + "/" + Podcasts.formatEpisodeTime(model.duration) + " | " + model.artist
548+ : Podcasts.formatEpisodeTime(model.position/1000) + "/" + Podcasts.formatEpisodeTime(model.duration) + " | " + model.artist
549549 subtitle.color: podbird.appTheme.baseSubText
550550
551551 Image {
@@ -747,9 +747,9 @@ Tab {
747747 episodesModel.append({"guid" : episode.guid, "listened" : episode.listened, "published": episode.published, "name" : episode.name, "description" : episode.description, "duration" : episode.duration, "position" : episode.position, "downloadedfile" : episode.downloadedfile, "image" : podcast.image, "artist" : podcast.artist, "audiourl" : episode.audiourl, "queued": episode.queued, "favourited": episode.favourited, "diff": "Older"})
748748 }
749749 } else if (diff >= 7) {
750− if (episode.downloadedfile != null) {
751− episodesModel.append({"guid" : episode.guid, "listened" : episode.listened, "published": episode.published, "name" : episode.name, "description" : episode.description, "duration" : episode.duration, "position" : episode.position, "downloadedfile" : episode.downloadedfile, "image" : podcast.image, "artist" : podcast.artist, "audiourl" : episode.audiourl, "queued": episode.queued, "favourited": episode.favourited, "diff": "Older"})
752− }
750+ if (episode.downloadedfile != null) {
751+ episodesModel.append({"guid" : episode.guid, "listened" : episode.listened, "published": episode.published, "name" : episode.name, "description" : episode.description, "duration" : episode.duration, "position" : episode.position, "downloadedfile" : episode.downloadedfile, "image" : podcast.image, "artist" : podcast.artist, "audiourl" : episode.audiourl, "queued": episode.queued, "favourited": episode.favourited, "diff": "Older"})
752+ }
753753 }
754754 }
755755
app/ui/FullPlayingView.qml+28−5
@@ -133,10 +133,24 @@ Item {
133133 maximumValue: player.duration
134134 value: player.position
135135 height: units.gu(2)
136−
137− onValueChanged: {
138− if (pressed) {
139− player.seek(value);
136+
137+ property bool seeking: false
138+ property bool seeked: false
139+
140+ onSeekingChanged: {
141+ if (seeking === false) {
142+ startTime.text = Podcasts.formatTime(player.position / 1000)
143+ }
144+ }
145+
146+ onPressedChanged: {
147+ seeking = pressed
148+
149+ if (!pressed) {
150+ seeked = true
151+ player.seek(value)
152+
153+ startTime.text = Podcasts.formatTime(value / 1000)
140154 }
141155 }
142156
@@ -146,7 +160,16 @@ Item {
146160
147161 Connections {
148162 target: player
149− onPositionChanged: scrubber.value = player.position
163+ onPositionChanged: {
164+ // seeked is a workaround for bug 1310706 as the first position after a seek is sometimes invalid (0)
165+ if (scrubber.seeking === false && !scrubber.seeked) {
166+ startTime.text = Podcasts.formatTime(player.position / 1000)
167+ endTime.text = Podcasts.formatTime(player.duration / 1000)
168+
169+ scrubber.value = player.position
170+ }
171+ scrubber.seeked = false;
172+ }
150173 }
151174
152175 Label {
app/ui/SettingsPage.qml+14
@@ -180,6 +180,20 @@ Page {
180180 onClicked: PopupUtils.open(skipBackDialog, settingsPage);
181181 }
182182
183+ ListItem {
184+ ListItemLayout {
185+ id: continueWhereStopped
186+ title.text: i18n.tr("Continue where stopped")
187+ Switch {
188+ SlotsLayout.position: SlotsLayout.Last
189+ checked: podbird.settings.continueWhereStopped
190+ onClicked: podbird.settings.continueWhereStopped = checked
191+ }
192+ }
193+ divider.visible: false
194+ height: gridViewLayout.height
195+ }
196+
183197 HeaderListItem {
184198 title.text: i18n.tr("Podcast Episode Settings")
185199 }