Skip to content

Commit

Permalink
Merge pull request #228 from THEOplayer/bugfix/android_audio_selection
Browse files Browse the repository at this point in the history
Bugfix/android audio selection
  • Loading branch information
tvanlaerhoven authored Nov 24, 2023
2 parents e6448f8 + 13979f2 commit 31f95a4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- Fixed an issue on iOS and Android were selecting an audio, video or text track that has a `uid` with value `0`, would fail.

## [3.1.0] - 23-10-27

### Changed
Expand Down
8 changes: 8 additions & 0 deletions android/src/main/java/com/theoplayer/player/PlayerModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ class PlayerModule(context: ReactApplicationContext) : ReactContextBaseJavaModul

@ReactMethod
fun setSelectedAudioTrack(tag: Int, uid: Int) {
if (uid == -1) {
// Do not allow disabling all audio tracks
return
}
viewResolver.resolveViewByTag(tag) { view: ReactTHEOplayerView? ->
view?.player?.let {
for (track in it.audioTracks) {
Expand All @@ -109,6 +113,10 @@ class PlayerModule(context: ReactApplicationContext) : ReactContextBaseJavaModul

@ReactMethod
fun setSelectedVideoTrack(tag: Int, uid: Int) {
if (uid == -1) {
// Do not allow disabling all video tracks
return
}
viewResolver.resolveViewByTag(tag) { view: ReactTHEOplayerView? ->
view?.player?.let {
for (track in it.videoTracks) {
Expand Down
6 changes: 3 additions & 3 deletions src/internal/adapter/THEOplayerAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ export class THEOplayerAdapter extends DefaultEventDispatcher<PlayerEventMap> im
return;
}
this._state.selectedAudioTrack = trackUid;
NativeModules.PlayerModule.setSelectedAudioTrack(this._view.nativeHandle, trackUid || -1);
NativeModules.PlayerModule.setSelectedAudioTrack(this._view.nativeHandle, (trackUid !== undefined) ? trackUid : -1);
}

get videoTracks(): MediaTrack[] {
Expand All @@ -408,7 +408,7 @@ export class THEOplayerAdapter extends DefaultEventDispatcher<PlayerEventMap> im
}
this._state.selectedVideoTrack = trackUid;
this._state.targetVideoQuality = undefined;
NativeModules.PlayerModule.setSelectedVideoTrack(this._view.nativeHandle, trackUid || -1);
NativeModules.PlayerModule.setSelectedVideoTrack(this._view.nativeHandle, (trackUid !== undefined) ? trackUid : -1);
}

get textTracks(): TextTrack[] {
Expand All @@ -431,7 +431,7 @@ export class THEOplayerAdapter extends DefaultEventDispatcher<PlayerEventMap> im
track.mode = TextTrackMode.disabled;
}
});
NativeModules.PlayerModule.setSelectedTextTrack(this._view.nativeHandle, trackUid || -1);
NativeModules.PlayerModule.setSelectedTextTrack(this._view.nativeHandle, (trackUid !== undefined) ? trackUid : -1);
}

get textTrackStyle(): TextTrackStyle {
Expand Down

0 comments on commit 31f95a4

Please sign in to comment.