141
id: singleDownloadComponent
143
id: singleDownloadObject
144
property string image
145
property string title
148
showInIndicator: true
149
title: singleDownloadObject.title
154
function downloadEpisode(image, title, guid, url) {
155
var singleDownload = singleDownloadComponent.createObject(podbird, {"image": image, "title": title, "guid": guid})
156
singleDownload.download(url)
143
property var queue: []
144
property string downloadingGuid
162
property string downloadingGuid: downloads.length > 0 ? downloads[0].guid : "NULL"
163
property int progress: downloads.length > 0 ? downloads[0].progress : 0
166
onDownloadFinished: {
147
167
var db = Podcasts.init();
148
168
var finalLocation = fileManager.saveDownload(path);
149
169
db.transaction(function (tx) {
150
tx.executeSql("UPDATE Episode SET downloadedfile=?, queued=0 WHERE guid=?", [finalLocation, downloadingGuid]);
152
if (queue.length > 0) {
153
downloadingGuid = queue[0][0];
154
download(queue[0][1]);
156
downloadingGuid = "";
170
tx.executeSql("UPDATE Episode SET downloadedfile=?, queued=0 WHERE guid=?", [finalLocation, download.guid]);
161
function addDownload(guid, url) {
162
queue.push([guid, url]);
163
if (queue.length == 1) {
164
downloadingGuid = guid;
170
// UserMetrics to show Podbird stats on welcome screen
173
name: "podcast-metrics"
174
// TRANSLATORS: this refers to a number of songs greater than one. The actual number will be prepended to the string automatically (plural forms are not yet fully supported in usermetrics, the library that displays that string)
175
format: i18n.tr("Podcasts listened to today: <b>%1</b>")
176
emptyFormat: i18n.tr("No podcasts listened to today")
177
domain: "com.mikeasoft.podbird"
180
// Load the media player only when the user starts to play some media. This
181
// should improve app-startup slightly.
184
sourceComponent: currentUrl != "" ? playerComponent : undefined
192
property bool podcastCounted: false
197
podcastCounted = false
201
if (currentGuid == "" || duration <= 0) {
205
if (position > 10000 && !podcastCounted) {
206
podcastCounted = true
207
podcastsMetric.increment()
208
console.log("[LOG]: Podcast User metric incremented")
211
var db = Podcasts.init();
212
db.transaction(function (tx) {
213
tx.executeSql("UPDATE Episode SET position=? WHERE guid=?", [position >= duration ? 120 : position, currentGuid]);
214
if (position >= duration - 120) {
215
tx.executeSql("UPDATE Episode SET listened = 1 WHERE guid=?", [currentGuid]);
175
console.log("[ERROR]: " + download.errorMessage)
182
// Wrapper function around decodeURIComponent() to prevent exceptions
183
// from bubbling up to the app.
184
function decodeFileURI(filename)
186
var newFilename = "";
188
newFilename = decodeURIComponent(filename);
190
newFilename = filename;
191
console.log("Unicode decoding error:", filename, e.message)
197
function metaForSource(source) {
205
source = source.toString()
207
return Podcasts.lookup(decodeFileURI(source)) || blankMeta;
211
if (playbackState === MediaPlayer.PlayingState) {
218
function playEpisode(guid, image, name, artist, url) {
219
// Clear current queue
220
player.playlist.clear()
221
Podcasts.clearQueue()
223
// Add episode to queue
224
Podcasts.addItemToQueue(guid, image, name, artist, url)
225
player.playlist.addItem(url)
231
function addEpisodeToQueue(guid, image, name, artist, url) {
232
Podcasts.addItemToQueue(guid, image, name, artist, url)
233
player.playlist.addItem(url)
235
// If added episode is the first one in the queue, then set the current metadata
236
// so that the bottom player controls will be shown, allowing the user to play
237
// the episode if he chooses to.
238
if (player.playlist.itemCount === 0) {
241
currentArtist = artist
247
property bool endOfMedia: false
248
property double progress: 0
251
playbackMode: Playlist.Sequential
253
readonly property bool canGoPrevious: currentIndex !== 0
254
readonly property bool canGoNext: currentIndex !== itemCount - 1
256
onCurrentItemSourceChanged: {
257
var meta = player.metaForSource(currentItemSource)
259
currentName = meta.name
260
currentArtist = meta.artist
261
currentImage = meta.image
262
currentGuid = meta.guid
267
if (status === MediaPlayer.EndOfMedia) {
268
console.log("[LOG]: End of Media. Stopping.")
275
if (playlist.itemCount > 0) {
277
// We just ended media, so jump to start of playlist
278
playlist.currentIndex = 0;
280
// Play then pause otherwise when we come from EndOfMedia
281
// it calls next() until EndOfMedia again.
288
// Always reset endOfMedia