Skip to content

Commit 060a9b6

Browse files
committed
[wrapper] Fixed autoStart in Player::open
1 parent af8a7c6 commit 060a9b6

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

dartvlc/internal/setters.hpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ class PlayerSetters: public PlayerEvents {
1919
public:
2020
void open(MediaSource* mediaSource, bool autoStart = true) {
2121
/* Freed the previous `Media` objects when a new `Playlist` or `Media` is opened. */
22+
this->state->isStarted = false;
23+
this->stop();
2224
for (Media* media: this->state->medias->medias) {
2325
delete media;
2426
}
25-
this->stop();
2627
this->state->medias->medias = {};
2728
this->mediaList = VLC::MediaList(this->instance);
2829
if (mediaSource->mediaSourceType() == "MediaSourceType.media") {
@@ -46,14 +47,20 @@ class PlayerSetters: public PlayerEvents {
4647
this->state->isPlaylist = true;
4748
}
4849
this->_onOpenCallback(this->mediaList.itemAtIndex(0));
49-
this->mediaListPlayer.playItemAtIndex(0);
5050
this->state->index = 0;
5151
this->state->isPlaying = this->mediaListPlayer.isPlaying();
5252
this->state->isValid = this->mediaListPlayer.isValid();
53+
if (autoStart) this->play();
5354
}
5455

5556
void play() {
56-
this->mediaListPlayer.play();
57+
if (!this->state->isStarted) {
58+
this->mediaListPlayer.playItemAtIndex(0);
59+
this->state->isStarted = true;
60+
}
61+
else {
62+
this->mediaListPlayer.play();
63+
}
5764
}
5865

5966
void pause() {
@@ -63,7 +70,13 @@ class PlayerSetters: public PlayerEvents {
6370
}
6471

6572
void playOrPause() {
66-
this->mediaListPlayer.pause();
73+
if (!this->state->isStarted) {
74+
this->mediaListPlayer.playItemAtIndex(0);
75+
this->state->isStarted = true;
76+
}
77+
else {
78+
this->mediaListPlayer.pause();
79+
}
6780
}
6881

6982
void stop() {

dartvlc/internal/state.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class PlayerState {
2828
float rate = 1.0;
2929
bool isPlaylist = false;
3030
Device* device = nullptr;
31+
/* NOTE: Used for autoStart. */
32+
bool isStarted = false;
3133
/* TODO: Not used yet.
3234
Equalizer* equalizer = nullptr;
3335
*/

0 commit comments

Comments
 (0)