@@ -245,6 +245,7 @@ MainView {
245 artist: "",
245 artist: "",
246 image: "",
246 image: "",
247 guid: "",
247 guid: "",
250 source = source.toString()
251 source = source.toString()
@@ -255,26 +256,50 @@ MainView {
255 function toggle() {
256 function toggle() {
256 if (playbackState === MediaPlayer.PlayingState) {
257 if (playbackState === MediaPlayer.PlayingState) {
259+ // Save the current position when we pause
263+ // Clear the last saved position when we start playing again
268+ function savePosition() {
270+ var db = Podcasts.init()
271+ db.transaction(function (tx) {
272+ tx.executeSql("UPDATE Episode SET position=? WHERE guid=?", [player.position, currentGuid])
273+ tx.executeSql("UPDATE Queue SET position=? WHERE guid=?", [player.position, currentGuid])
278+ function clearPosition() {
280+ var db = Podcasts.init()
281+ db.transaction(function (tx) {
282+ tx.executeSql("UPDATE Episode SET position=NULL WHERE guid=?", [currentGuid])
263− function playEpisode(guid, image, name, artist, url) {
287+ function playEpisode(guid, image, name, artist, url, position) {
264 // Clear current queue
288 // Clear current queue
265 player.playlist.clear()
289 player.playlist.clear()
266 Podcasts.clearQueue()
290 Podcasts.clearQueue()
268 // Add episode to queue
292 // Add episode to queue
269− Podcasts.addItemToQueue(guid, image, name, artist, url)
293+ Podcasts.addItemToQueue(guid, image, name, artist, url, position)
270 player.playlist.addItem(url)
294 player.playlist.addItem(url)
272 // Play episode
296 // Play episode
297+ pendingSeek = position
273 player.play()
298 player.play()
276− function addEpisodeToQueue(guid, image, name, artist, url) {
301+ function addEpisodeToQueue(guid, image, name, artist, url, position) {
277− Podcasts.addItemToQueue(guid, image, name, artist, url)
302+ Podcasts.addItemToQueue(guid, image, name, artist, url, position)
278 player.playlist.addItem(url)
303 player.playlist.addItem(url)
280 // If added episode is the first one in the queue, then set the current metadata
305 // If added episode is the first one in the queue, then set the current metadata
@@ -286,11 +311,13 @@ MainView {
286 currentArtist = artist
311 currentArtist = artist
287 currentImage = image
312 currentImage = image
288 currentUrl = url
313 currentUrl = url
314+ pendingSeek = position
292 property bool endOfMedia: false
318 property bool endOfMedia: false
293 property double progress: 0
319 property double progress: 0
320+ property int pendingSeek: 0
295 playlist: Playlist {
322 playlist: Playlist {
296 playbackMode: Playlist.Sequential
323 playbackMode: Playlist.Sequential
@@ -305,11 +332,28 @@ MainView {
305 currentArtist = meta.artist
332 currentArtist = meta.artist
306 currentImage = meta.image
333 currentImage = meta.image
307 currentGuid = meta.guid
334 currentGuid = meta.guid
335+ player.pendingSeek = meta.position
339+ onPlaybackStateChanged: {
340+ if (playbackState === MediaPlayer.PlayingState && pendingSeek !== 0) {
341+ player.seek(pendingSeek)
342+ player.clearPosition()
311 onStatusChanged: {
347 onStatusChanged: {
312− if (status === MediaPlayer.EndOfMedia) {
348+ if (status === MediaPlayer.Loading) {
349+ if (playbackState === MediaPlayer.PlayingState && pendingSeek !== 0) {
350+ player.seek(pendingSeek)
351+ player.clearPosition()
356+ } else if (status === MediaPlayer.EndOfMedia) {
313 console.log("[LOG]: End of Media. Stopping.")
357 console.log("[LOG]: End of Media. Stopping.")
314 endOfMedia = true
358 endOfMedia = true
@@ -325,14 +369,17 @@ MainView {
325 // Play then pause otherwise when we come from EndOfMedia
369 // Play then pause otherwise when we come from EndOfMedia
326 // it calls next() until EndOfMedia again.
370 // it calls next() until EndOfMedia again.
333 // Always reset endOfMedia
376 // Always reset endOfMedia
334 endOfMedia = false
377 endOfMedia = false
380+ Component.onDestruction: {
338 PageStack {
385 PageStack {