@@ -19,10 +19,11 @@ class PlayerSetters: public PlayerEvents {
19
19
public:
20
20
void open (MediaSource* mediaSource, bool autoStart = true ) {
21
21
/* Freed the previous `Media` objects when a new `Playlist` or `Media` is opened. */
22
+ this ->state ->isStarted = false ;
23
+ this ->stop ();
22
24
for (Media* media: this ->state ->medias ->medias ) {
23
25
delete media;
24
26
}
25
- this ->stop ();
26
27
this ->state ->medias ->medias = {};
27
28
this ->mediaList = VLC::MediaList (this ->instance );
28
29
if (mediaSource->mediaSourceType () == " MediaSourceType.media" ) {
@@ -46,14 +47,20 @@ class PlayerSetters: public PlayerEvents {
46
47
this ->state ->isPlaylist = true ;
47
48
}
48
49
this ->_onOpenCallback (this ->mediaList .itemAtIndex (0 ));
49
- this ->mediaListPlayer .playItemAtIndex (0 );
50
50
this ->state ->index = 0 ;
51
51
this ->state ->isPlaying = this ->mediaListPlayer .isPlaying ();
52
52
this ->state ->isValid = this ->mediaListPlayer .isValid ();
53
+ if (autoStart) this ->play ();
53
54
}
54
55
55
56
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
+ }
57
64
}
58
65
59
66
void pause () {
@@ -63,7 +70,13 @@ class PlayerSetters: public PlayerEvents {
63
70
}
64
71
65
72
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
+ }
67
80
}
68
81
69
82
void stop () {
0 commit comments