Skip to content

Commit 7191cb7

Browse files
committed
Wrapper: Add start_time & stop_time handling to Media
1 parent 44b6133 commit 7191cb7

File tree

5 files changed

+54
-29
lines changed

5 files changed

+54
-29
lines changed

dartvlc/api/api.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,16 @@ void PlayerOpen(int32_t id, bool auto_start, const char** source,
8383
int32_t source_size) {
8484
std::vector<std::shared_ptr<Media>> medias{};
8585
Player* player = g_players->Get(id);
86-
for (int32_t index = 0; index < 2 * source_size; index += 2) {
86+
for (int32_t index = 0; index < 4 * source_size; index += 4) {
8787
std::shared_ptr<Media> media;
8888
const char* type = source[index];
8989
const char* resource = source[index + 1];
90+
const char* start_time = source[index + 2];
91+
const char* stop_time = source[index + 3];
9092
if (strcmp(type, "MediaType.file") == 0)
91-
media = Media::file(resource, false);
93+
media = Media::file(resource, false, 10000, start_time, stop_time);
9294
else if (strcmp(type, "MediaType.network") == 0)
93-
media = Media::network(resource, false);
95+
media = Media::network(resource, false, 10000, start_time, stop_time);
9496
else
9597
media = Media::directShow(resource);
9698
medias.emplace_back(media);
@@ -238,7 +240,7 @@ const char** MediaParse(Dart_Handle object, const char* type,
238240
Dart_NewFinalizableHandle_DL(
239241
object, reinterpret_cast<void*>(values), sizeof(values),
240242
static_cast<Dart_HandleFinalizer>(MediaClearVector));
241-
for (const auto& [key, value] : *metas) {
243+
for (const auto & [ key, value ] : *metas) {
242244
values->emplace_back(value.c_str());
243245
}
244246
return values->data();
@@ -310,7 +312,7 @@ DartDeviceList* DevicesAll(Dart_Handle object) {
310312
static DartEqualizer* EqualizerToDart(const Equalizer* equalizer, int32_t id,
311313
Dart_Handle dart_handle) {
312314
auto wrapper = new DartObjects::Equalizer();
313-
for (const auto& [band, amp] : equalizer->band_amps()) {
315+
for (const auto & [ band, amp ] : equalizer->band_amps()) {
314316
wrapper->bands.emplace_back(band);
315317
wrapper->amps.emplace_back(amp);
316318
}

dartvlc/api/eventmanager.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ inline void OnPlayPauseStop(int32_t id, PlayerState* state) {
3939

4040
Dart_CObject type_object;
4141
type_object.type = Dart_CObject_kString;
42-
type_object.value.as_string = "playbackEvent";
42+
type_object.value.as_string = const_cast<char*>("playbackEvent");
4343

4444
Dart_CObject is_playing_object;
4545
is_playing_object.type = Dart_CObject_kBool;
@@ -66,7 +66,7 @@ inline void OnPosition(int32_t id, PlayerState* state) {
6666

6767
Dart_CObject type_object;
6868
type_object.type = Dart_CObject_kString;
69-
type_object.value.as_string = "positionEvent";
69+
type_object.value.as_string = const_cast<char*>("positionEvent");
7070

7171
Dart_CObject index_object;
7272
index_object.type = Dart_CObject_kInt32;
@@ -97,7 +97,7 @@ inline void OnComplete(int32_t id, PlayerState* state) {
9797

9898
Dart_CObject type_object;
9999
type_object.type = Dart_CObject_kString;
100-
type_object.value.as_string = "completeEvent";
100+
type_object.value.as_string = const_cast<char*>("completeEvent");
101101

102102
Dart_CObject is_completed_object;
103103
is_completed_object.type = Dart_CObject_kBool;
@@ -120,7 +120,7 @@ inline void OnVolume(int32_t id, PlayerState* state) {
120120

121121
Dart_CObject type_object;
122122
type_object.type = Dart_CObject_kString;
123-
type_object.value.as_string = "volumeEvent";
123+
type_object.value.as_string = const_cast<char*>("volumeEvent");
124124

125125
Dart_CObject volume_object;
126126
volume_object.type = Dart_CObject_kDouble;
@@ -142,7 +142,7 @@ inline void OnRate(int32_t id, PlayerState* state) {
142142

143143
Dart_CObject type_object;
144144
type_object.type = Dart_CObject_kString;
145-
type_object.value.as_string = "rateEvent";
145+
type_object.value.as_string = const_cast<char*>("rateEvent");
146146

147147
Dart_CObject rate_object;
148148
rate_object.type = Dart_CObject_kDouble;
@@ -166,7 +166,7 @@ inline void OnOpen(int32_t id, PlayerState* state) {
166166

167167
Dart_CObject type_object;
168168
type_object.type = Dart_CObject_kString;
169-
type_object.value.as_string = "openEvent";
169+
type_object.value.as_string = const_cast<char*>("openEvent");
170170

171171
Dart_CObject index_object;
172172
index_object.type = Dart_CObject_kInt32;
@@ -179,7 +179,7 @@ inline void OnOpen(int32_t id, PlayerState* state) {
179179
auto types_objects =
180180
std::unique_ptr<Dart_CObject[]>(new Dart_CObject[media_items.size()]);
181181
auto types_object_refs =
182-
std::unique_ptr<Dart_CObject*[]>(new Dart_CObject*[media_items.size()]);
182+
std::unique_ptr<Dart_CObject* []>(new Dart_CObject*[media_items.size()]);
183183
std::vector<std::string> types_str(media_items.size());
184184
std::vector<const char*> types_ptr(media_items.size());
185185
for (int32_t i = 0; i < media_items.size(); i++) {
@@ -198,7 +198,7 @@ inline void OnOpen(int32_t id, PlayerState* state) {
198198
auto resources_objects =
199199
std::unique_ptr<Dart_CObject[]>(new Dart_CObject[media_items.size()]);
200200
auto resources_object_refs =
201-
std::unique_ptr<Dart_CObject*[]>(new Dart_CObject*[media_items.size()]);
201+
std::unique_ptr<Dart_CObject* []>(new Dart_CObject*[media_items.size()]);
202202
std::vector<std::string> resources_str(media_items.size());
203203
std::vector<const char*> resources_ptr(media_items.size());
204204
for (int32_t i = 0; i < media_items.size(); i++) {
@@ -233,7 +233,7 @@ inline void OnVideoDimensions(int32_t id, int32_t video_width,
233233

234234
Dart_CObject type_object;
235235
type_object.type = Dart_CObject_kString;
236-
type_object.value.as_string = "videoDimensionsEvent";
236+
type_object.value.as_string = const_cast<char*>("videoDimensionsEvent");
237237

238238
Dart_CObject video_width_object;
239239
video_width_object.type = Dart_CObject_kInt32;
@@ -260,7 +260,7 @@ inline void OnVideo(int32_t id, int size, uint8_t* frame) {
260260

261261
Dart_CObject type_object;
262262
type_object.type = Dart_CObject_kString;
263-
type_object.value.as_string = "videoEvent";
263+
type_object.value.as_string = const_cast<char*>("videoEvent");
264264

265265
Dart_CObject frame_object;
266266
frame_object.type = Dart_CObject_kTypedData;
@@ -284,7 +284,7 @@ inline void OnBuffering(int32_t id, float buffering) {
284284

285285
Dart_CObject type_object;
286286
type_object.type = Dart_CObject_kString;
287-
type_object.value.as_string = "bufferingEvent";
287+
type_object.value.as_string = const_cast<char*>("bufferingEvent");
288288

289289
Dart_CObject buffering_object;
290290
buffering_object.type = Dart_CObject_kDouble;

dartvlc/internal/events.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ class PlayerEvents : public PlayerGetters {
117117
open_callback_(*vlc_media_ptr.get());
118118
}
119119

120-
std::function<void(int32_t, int32_t)> video_dimension_callback_ =
121-
[=](int32_t, int32_t) -> void {};
120+
std::function<void(int32_t, int32_t)> video_dimension_callback_ = [=](
121+
int32_t, int32_t) -> void {};
122122

123123
void OnVideoDimensionsCallback() {
124124
int32_t video_width = 0;
@@ -144,9 +144,8 @@ class PlayerEvents : public PlayerGetters {
144144
vlc_media_player_.setVideoCallbacks(
145145
std::bind(&PlayerEvents::OnVideoLockCallback, this,
146146
std::placeholders::_1),
147-
nullptr,
148-
std::bind(&PlayerEvents::OnVideoPictureCallback, this,
149-
std::placeholders::_1));
147+
nullptr, std::bind(&PlayerEvents::OnVideoPictureCallback, this,
148+
std::placeholders::_1));
150149
vlc_media_player_.setVideoFormatCallbacks(
151150
[=](char* chroma, uint32_t* w, uint32_t* h, uint32_t* p,
152151
uint32_t* l) -> int32_t {
@@ -207,8 +206,8 @@ class PlayerEvents : public PlayerGetters {
207206
stop_callback_();
208207
}
209208

210-
std::function<void(int32_t)> position_callback_ =
211-
[=](int32_t position) -> void {};
209+
std::function<void(int32_t)> position_callback_ = [=](
210+
int32_t position) -> void {};
212211

213212
void OnPositionCallback(float relative_position) {
214213
state()->is_playing_ = vlc_media_player_.isPlaying();

dartvlc/internal/setters.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ class PlayerSetters : public PlayerEvents {
2828
std::dynamic_pointer_cast<Media>(media_source);
2929
VLC::Media vlc_media = VLC::Media(vlc_instance_, media->location(),
3030
VLC::Media::FromLocation);
31+
if (media->start_time() != "") {
32+
vlc_media.addOption(media->start_time());
33+
}
34+
if (media->stop_time() != "") {
35+
vlc_media.addOption(media->stop_time());
36+
}
3137
vlc_media_list_.addMedia(vlc_media);
3238
vlc_media_list_player_.setMediaList(vlc_media_list_);
3339
state()->medias()->medias() = {media};
@@ -39,6 +45,12 @@ class PlayerSetters : public PlayerEvents {
3945
for (std::shared_ptr<Media>& media : playlist->medias()) {
4046
VLC::Media vlc_media = VLC::Media(vlc_instance_, media->location(),
4147
VLC::Media::FromLocation);
48+
if (media->start_time() != "") {
49+
vlc_media.addOption(media->start_time());
50+
}
51+
if (media->stop_time() != "") {
52+
vlc_media.addOption(media->stop_time());
53+
}
4254
vlc_media_list_.addMedia(vlc_media);
4355
state()->medias()->medias().emplace_back(media);
4456
}

dartvlc/mediasource/media.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class Media : public MediaSource {
3030
std::string& media_type() { return media_type_; };
3131
std::string& resource() { return resource_; };
3232
std::string& location() { return location_; };
33+
std::string& start_time() { return start_time_; };
34+
std::string& stop_time() { return stop_time_; };
3335
std::map<std::string, std::string>& metas() { return metas_; };
3436

3537
static std::shared_ptr<Media> create(std::string_view type,
@@ -45,21 +47,29 @@ class Media : public MediaSource {
4547
}
4648

4749
static std::shared_ptr<Media> file(std::string path, bool parse = false,
48-
int32_t timeout = 10000) {
50+
int32_t timeout = 10000,
51+
std::string start_time = "",
52+
std::string stop_time = "") {
4953
std::shared_ptr<Media> media = std::make_shared<Media>();
5054
media->resource_ = path;
5155
media->location_ = "file:///" + path;
5256
media->media_type_ = kMediaTypeFile;
57+
media->start_time_ = start_time;
58+
media->stop_time_ = stop_time;
5359
if (parse) media->parse(timeout);
5460
return media;
5561
}
5662

5763
static std::shared_ptr<Media> network(std::string url, bool parse = false,
58-
int32_t timeout = 10000) {
64+
int32_t timeout = 10000,
65+
std::string start_time = "",
66+
std::string stop_time = "") {
5967
std::shared_ptr<Media> media = std::make_shared<Media>();
6068
media->resource_ = url;
6169
media->location_ = url;
6270
media->media_type_ = kMediaTypeNetwork;
71+
media->start_time_ = start_time;
72+
media->stop_time_ = stop_time;
6373
if (parse) media->parse(timeout);
6474
return media;
6575
}
@@ -114,10 +124,12 @@ class Media : public MediaSource {
114124
std::string Type() { return "MediaSourceType.media"; }
115125

116126
private:
117-
std::string media_type_;
118-
std::string resource_;
119-
std::string location_;
120-
std::map<std::string, std::string> metas_;
127+
std::string media_type_ = "";
128+
std::string resource_ = "";
129+
std::string location_ = "";
130+
std::string start_time_ = "";
131+
std::string stop_time_ = "";
132+
std::map<std::string, std::string> metas_ = {};
121133
};
122134

123135
#endif

0 commit comments

Comments
 (0)