@@ -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 {