@@ -42,13 +42,6 @@ MainView {
42 theme.name: settings.themeName == "Dark.qml" ? "Ubuntu.Components.Themes.SuruDark"
42 theme.name: settings.themeName == "Dark.qml" ? "Ubuntu.Components.Themes.SuruDark"
43 : "Ubuntu.Components.Themes.Ambiance"
43 : "Ubuntu.Components.Themes.Ambiance"
45− Component.onDestruction: {
46− var db = Podcasts.init()
47− db.transaction(function (tx) {
48− tx.executeSql('UPDATE Episode SET queued=0 WHERE queued=1');
50− Podcasts.clearQueue()
53 // RefreshModel function to call refreshModel() function of the tab currently
46 // RefreshModel function to call refreshModel() function of the tab currently
54 // visible on application start.
47 // visible on application start.
@@ -62,9 +55,6 @@ MainView {
63 Component.onCompleted: {
56 Component.onCompleted: {
64 var db = Podcasts.init()
57 var db = Podcasts.init()
65− db.transaction(function (tx) {
66− tx.executeSql('UPDATE Episode SET queued=0 WHERE queued=1');
69 var today = new Date()
59 var today = new Date()
70 // Only automatically check for podcasts on launch once every 12 hours
60 // Only automatically check for podcasts on launch once every 12 hours
@@ -126,6 +116,8 @@ MainView {
126 property bool showListView: true
116 property bool showListView: true
127 property int skipForward: 30
117 property int skipForward: 30
128 property int skipBack: 10
118 property int skipBack: 10
119+ property bool continueWhereStopped: true
120+ property int playlistIndex: -1
129 property bool downloadOverWifiOnly: true
121 property bool downloadOverWifiOnly: true
@@ -232,14 +224,15 @@ MainView {
232 // but media-hub doesn't report it correctly
224 // but media-hub doesn't report it correctly
233 console.log("Starting playback")
225 console.log("Starting playback")
234 player.play()
226 player.play()
235− player.restorePosition()
239 MediaPlayer {
230 MediaPlayer {
240 id: player
231 id: player
242− onPositionChanged: console.log("DEBUG: player position changed to: ", position)
233+ onPositionChanged: {
244 // Wrapper function around decodeURIComponent() to prevent exceptions
237 // Wrapper function around decodeURIComponent() to prevent exceptions
245 // from bubbling up to the app.
238 // from bubbling up to the app.
@@ -277,26 +270,42 @@ MainView {
277 savePosition()
270 savePosition()
280− // Clear the last saved position when we start playing again
285 function savePosition() {
276 function savePosition() {
277+ podbird.settings.playlistIndex = playlist.currentIndex
286 if (currentGuid) {
278 if (currentGuid) {
287 var db = Podcasts.init()
279 var db = Podcasts.init()
288 db.transaction(function (tx) {
280 db.transaction(function (tx) {
289 tx.executeSql("UPDATE Episode SET position=? WHERE guid=?", [player.position, currentGuid])
281 tx.executeSql("UPDATE Episode SET position=? WHERE guid=?", [player.position, currentGuid])
290 tx.executeSql("UPDATE Queue SET position=? WHERE guid=?", [player.position, currentGuid])
282 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])
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)
299+ if(playlist.itemCount > podbird.settings.playlistIndex)
300+ playlist.currentIndex = podbird.settings.playlistIndex
295 function restorePosition() {
303 function restorePosition() {
296− if (playbackState === MediaPlayer.PlayingState && pendingSeek !== 0) {
304+ if(playbackState === MediaPlayer.PlayingState && status === MediaPlayer.Loaded && pendingSeek){
297− player.seek(pendingSeek)
305+ //ugly hack because seek function does not seems to work async
298− player.clearPosition()
306+ var p = pendingSeek
299− pendingSeek = 0;
307+ pendingSeek = 0
@@ -345,7 +354,6 @@ MainView {
347 property bool endOfMedia: false
356 property bool endOfMedia: false
348− property double progress: 0
349 property int pendingSeek: 0
357 property int pendingSeek: 0
351 playlist: Playlist {
359 playlist: Playlist {
@@ -361,16 +369,10 @@ MainView {
361 currentArtist = meta.artist
369 currentArtist = meta.artist
362 currentImage = meta.image
370 currentImage = meta.image
363 currentGuid = meta.guid
371 currentGuid = meta.guid
364− player.pendingSeek = meta.position
372+ player.pendingSeek = podbird.settings.continueWhereStopped && meta.position > 5000 ? meta.position : 0
365− console.log("DEBUG: player.pendingSeek: ", player.pendingSeek, " meta.position ", meta.position)
369− onPlaybackStateChanged: {
370− console.log("DEBUG: Restoring Position to: ", player.position)
374 onStatusChanged: {
376 onStatusChanged: {
375 if (status === MediaPlayer.EndOfMedia) {
377 if (status === MediaPlayer.EndOfMedia) {
376 console.log("[LOG]: End of Media. Stopping.")
378 console.log("[LOG]: End of Media. Stopping.")
@@ -399,6 +401,10 @@ MainView {
399 Component.onDestruction: {
401 Component.onDestruction: {
400 savePosition()
402 savePosition()
405+ Component.onCompleted: {
404 PageStack {
410 PageStack {