@@ -19,7 +19,7 @@ Player::Player(QMediaPlayer *parent)
19
19
connect (this , &QMediaPlayer::volumeChanged, this , &Player::volumeChanged);
20
20
connect (this , &QMediaPlayer::playbackRateChanged, this , &Player::speedChanged);
21
21
// connect(this, &QMediaPlayer::seekableChanged, this, &Player::seekableChanged); // broken on android
22
- // connect(this, &QMediaPlayer::bufferStatusChanged, this, &Player::bufferChanged);
22
+ // connect(this, &QMediaPlayer::bufferStatusChanged, this, &Player::bufferChanged); // broken
23
23
24
24
// exit app
25
25
connect (qApp, &QApplication::aboutToQuit, this , &Player::exitHandler);
@@ -52,24 +52,6 @@ QObject *Player::qmlInstance(QQmlEngine *engine, QJSEngine *scriptEngine)
52
52
}
53
53
54
54
55
- void Player::loadBook () {
56
- qDebug () << mCurrentBook ->title << mCurrentBook ->progress ;
57
- mSetPosition = -1 ;
58
- mProgressScale = 10000.0 /mCurrentBook ->duration ;
59
- mProgress = mCurrentBook ->progress ;
60
-
61
- playlist ()->clear ();
62
- for (auto chapter: mCurrentBook ->chapters )
63
- {
64
- QUrl url = QUrl::fromLocalFile (Database::instance ()->libraryPath () + chapter.path );
65
- playlist ()->addMedia (url);
66
- }
67
-
68
- // set a default item in the playlist
69
- setChapterIndex (0 );
70
-
71
- setProgress (mProgress );
72
- }
73
55
74
56
75
57
void Player::setChapterIndex (int xIndex) {
@@ -139,6 +121,7 @@ void Player::setPlaybackMode(QMediaPlaylist::PlaybackMode mode) {
139
121
140
122
qint64 Player::sliderValue () const {
141
123
// multiply by scale of the slider
124
+ qDebug () << " slider value" ;
142
125
return mProgress * mProgressScale ;
143
126
}
144
127
@@ -182,17 +165,21 @@ QString Player::titleText() const
182
165
183
166
void Player::positionChanged (qint64 xPosition)
184
167
{
185
- // dont change progress if media is changing
168
+
186
169
if (mSetPosition > xPosition) {
187
- if (QMediaPlayer::isSeekable ()) {
188
- qDebug () << " seekable!" ;
189
- setPosition (mSetPosition );
190
- setMuted (false );
191
- mSetPosition = -1 ;
192
- }
193
- return ;
170
+ // dont change progress if media is changing
171
+ if (!QMediaPlayer::isSeekable ())
172
+ return ;
173
+
174
+ qDebug () << " seekable!" ;
175
+ setPosition (mSetPosition );
176
+ setMuted (false );
177
+ mSetPosition = -1 ;
194
178
}
195
179
180
+ qDebug () << " position changed emit" ;
181
+
182
+
196
183
mProgress = mCurrentBook ->getStartProgressChapter (chapterIndex ()) + xPosition;
197
184
mCurrentBook ->progress = mProgress ;
198
185
Database::instance ()->writeBook (*mCurrentBook );
@@ -204,6 +191,7 @@ void Player::setProgress(qint64 xPosition) {
204
191
// this converts from book progress to
205
192
// chapter index
206
193
// chapter time -> position
194
+ qDebug () << " setProgress" ;
207
195
int chapter_index = mCurrentBook ->getChapterIndex (xPosition);
208
196
qint64 chapter_position = mCurrentBook ->getChapterPosition (xPosition);
209
197
@@ -260,9 +248,34 @@ void Player::setCurrentItem(QString &xIndex)
260
248
if (mCurrentBook != nullptr && mCurrentBook ->path == xIndex)
261
249
return ;
262
250
263
- mCurrentBook = Database::instance ()->getLibraryItem (xIndex);
251
+
252
+ // save book progress
253
+ if (mCurrentBook != nullptr )
254
+ Database::instance ()->writeBook (*mCurrentBook );
255
+
256
+
257
+ // load the new book to playlist
258
+ playlist ()->clear ();
264
259
Settings::setValue (" current_item" , xIndex);
265
- loadBook ();
260
+ mCurrentBook = Database::instance ()->getLibraryItem (xIndex);
261
+
262
+ qDebug () << mCurrentBook ->title << mCurrentBook ->progress ;
263
+
264
+ mSetPosition = -1 ;
265
+ mProgressScale = 10000.0 /mCurrentBook ->duration ;
266
+ mProgress = mCurrentBook ->progress ;
267
+ emit progressChanged ();
268
+
269
+ for (auto chapter: mCurrentBook ->chapters )
270
+ {
271
+ QUrl url = QUrl::fromLocalFile (Database::instance ()->libraryPath () + chapter.path );
272
+ playlist ()->addMedia (url);
273
+ }
274
+
275
+ // set a default item in the playlist
276
+ // setChapterIndex(0);
277
+
278
+ setProgress (mProgress );
266
279
}
267
280
268
281
0 commit comments