Skip to content

Commit

Permalink
Added support for setting current audio track and getting audio track…
Browse files Browse the repository at this point in the history
… count
  • Loading branch information
exts committed Feb 7, 2022
1 parent 61f8180 commit 48a1440
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
10 changes: 10 additions & 0 deletions dartvlc/api/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ void PlayerTakeSnapshot(int32_t id, const char* file_path, int32_t width,
player->TakeSnapshot(file_path, width, height);
}

void PlayerSetAudioTrack(int32_t id, int32_t track) {
Player* player = g_players->Get(id);
player->SetAudioTrack(track);
}

int32_t PlayerAudioTrackCount(int32_t id) {
Player* player = g_players->Get(id);
return player->AudioTrackCount();
}

void MediaClearMap(void*, void* peer) {
delete reinterpret_cast<std::map<std::string, std::string>*>(peer);
}
Expand Down
4 changes: 4 additions & 0 deletions dartvlc/api/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ DLLEXPORT void PlayerMove(int32_t id, int32_t initial_index,
DLLEXPORT void PlayerTakeSnapshot(int32_t id, const char* file_path,
int32_t width, int32_t height);

DLLEXPORT void PlayerSetAudioTrack(int32_t id, int32_t track);

DLLEXPORT int32_t PlayerAudioTrackCount(int32_t id);

DLLEXPORT const char** MediaParse(Dart_Handle object, const char* type,
const char* resource, int32_t timeout);

Expand Down
8 changes: 8 additions & 0 deletions dartvlc/internal/setters.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,12 @@ class PlayerSetters : public PlayerEvents {
void SetVideoHeight(int32_t video_height) {
preferred_video_height_ = video_height;
}

void SetAudioTrack(int32_t track) {
vlc_media_player_.setAudioTrack(track);
}

int32_t AudioTrackCount() {
return vlc_media_player_.audioTrackCount();
}
};
8 changes: 8 additions & 0 deletions ffi/lib/src/internal/ffi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ abstract class PlayerFFI {
static final PlayerTakeSnapshotDart takeSnapshot = dynamicLibrary
.lookup<NativeFunction<PlayerTakeSnapshotCXX>>('PlayerTakeSnapshot')
.asFunction();

static final PlayerSetAudioTrackDart setAudioTrack = dynamicLibrary
.lookup<NativeFunction<PlayerSetAudioTrackCXX>>('PlayerSetAudioTrack')
.asFunction();

static final PlayerAudioTrackCountDart audioTrackCount = dynamicLibrary
.lookup<NativeFunction<PlayerAudioTrackCountCXX>>('PlayerAudioTrackCount')
.asFunction();
}

abstract class MediaFFI {
Expand Down
4 changes: 4 additions & 0 deletions ffi/lib/src/internal/typedefs/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@ typedef PlayerTakeSnapshotCXX = Void Function(
Int32 id, Pointer<Utf8> filePath, Int32 width, Int32 height);
typedef PlayerTakeSnapshotDart = void Function(
int id, Pointer<Utf8> filePath, int width, int height);
typedef PlayerSetAudioTrackCXX = Void Function(Int32 id, Int32 index);
typedef PlayerSetAudioTrackDart = void Function(int id, int index);
typedef PlayerAudioTrackCountCXX = Int32 Function(Int32 id);
typedef PlayerAudioTrackCountDart = int Function(int id);
13 changes: 13 additions & 0 deletions ffi/lib/src/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,19 @@ class Player {
);
}

/// Sets Current Audio Track for the current [MediaSource]
void setAudioTrack(int track) {
return PlayerFFI.setAudioTrack(this.id, track);
}

/// Gets audio track count from current [MediaSource]
int audioTrackCount() {
int count = PlayerFFI.audioTrackCount(this.id);
// for some reason this value returns 0 when no tracks exists
// and 2 or more if there's 1 or more audio tracks for this [MediaSource].
return count > 1 ? count - 1 : count;
}

/// Destroys the instance of [Player] & closes all [StreamController]s in it.
void dispose() {
this.currentController.close();
Expand Down

0 comments on commit 48a1440

Please sign in to comment.