Skip to content

Commit ec7d56a

Browse files
committed
feat(android): add audio track selection for ExoPlayer
- Implemented getAudioTracks() and selectAudioTrack() methods for Android video player using ExoPlayer - Removed Kotlin dependencies and switched back to pure Java implementation - Updated event listener to handle buffering states more accurately with start/end events - Simplified playback state handling by removing unnecessary state enum
1 parent c8ba0cc commit ec7d56a

27 files changed

+2962
-699
lines changed

packages/video_player/video_player_android/CHANGELOG.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
## 2.8.17
1+
## 2.9.0
22

3-
* Moves video event processing logic to Dart, and fixes an issue where buffer
4-
range would not be updated for a paused video.
5-
* Switches to Kotlin for Pigeon-generated code.
6-
* Adopts type-safe event channels for internal communication.
3+
* Implements `getAudioTracks()` and `selectAudioTrack()` methods for Android using ExoPlayer.
74

85
## 2.8.16
96

packages/video_player/video_player_android/android/build.gradle

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ group = 'io.flutter.plugins.videoplayer'
22
version = '1.0-SNAPSHOT'
33

44
buildscript {
5-
ext.kotlin_version = '2.2.10'
65
repositories {
76
google()
87
mavenCentral()
98
}
109

1110
dependencies {
1211
classpath 'com.android.tools.build:gradle:8.12.1'
13-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1412
}
1513
}
1614

@@ -22,7 +20,6 @@ rootProject.allprojects {
2220
}
2321

2422
apply plugin: 'com.android.library'
25-
apply plugin: 'kotlin-android'
2623

2724
android {
2825
namespace = "io.flutter.plugins.videoplayer"
@@ -41,13 +38,6 @@ android {
4138
sourceCompatibility = JavaVersion.VERSION_17
4239
targetCompatibility = JavaVersion.VERSION_17
4340
}
44-
kotlinOptions {
45-
jvmTarget = JavaVersion.VERSION_17.toString()
46-
}
47-
48-
sourceSets {
49-
main.java.srcDirs += 'src/main/kotlin'
50-
}
5141

5242
dependencies {
5343
def exoplayer_version = "1.5.1"

packages/video_player/video_player_android/android/src/main/java/io/flutter/plugins/videoplayer/ExoPlayerEventListener.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import androidx.media3.exoplayer.ExoPlayer;
1111

1212
public abstract class ExoPlayerEventListener implements Player.Listener {
13+
private boolean isBuffering = false;
1314
private boolean isInitialized = false;
1415
protected final ExoPlayer exoPlayer;
1516
protected final VideoPlayerCallbacks events;
@@ -46,34 +47,47 @@ public ExoPlayerEventListener(
4647
this.events = events;
4748
}
4849

50+
private void setBuffering(boolean buffering) {
51+
if (isBuffering == buffering) {
52+
return;
53+
}
54+
isBuffering = buffering;
55+
if (buffering) {
56+
events.onBufferingStart();
57+
} else {
58+
events.onBufferingEnd();
59+
}
60+
}
61+
4962
protected abstract void sendInitialized();
5063

5164
@Override
5265
public void onPlaybackStateChanged(final int playbackState) {
53-
PlatformPlaybackState platformState = PlatformPlaybackState.UNKNOWN;
5466
switch (playbackState) {
5567
case Player.STATE_BUFFERING:
56-
platformState = PlatformPlaybackState.BUFFERING;
68+
setBuffering(true);
69+
events.onBufferingUpdate(exoPlayer.getBufferedPosition());
5770
break;
5871
case Player.STATE_READY:
59-
platformState = PlatformPlaybackState.READY;
6072
if (!isInitialized) {
6173
isInitialized = true;
6274
sendInitialized();
6375
}
6476
break;
6577
case Player.STATE_ENDED:
66-
platformState = PlatformPlaybackState.ENDED;
78+
events.onCompleted();
6779
break;
6880
case Player.STATE_IDLE:
69-
platformState = PlatformPlaybackState.IDLE;
7081
break;
7182
}
72-
events.onPlaybackStateChanged(platformState);
83+
if (playbackState != Player.STATE_BUFFERING) {
84+
setBuffering(false);
85+
}
7386
}
7487

7588
@Override
7689
public void onPlayerError(@NonNull final PlaybackException error) {
90+
setBuffering(false);
7791
if (error.errorCode == PlaybackException.ERROR_CODE_BEHIND_LIVE_WINDOW) {
7892
// See
7993
// https://exoplayer.dev/live-streaming.html#behindlivewindowexception-and-error_code_behind_live_window

0 commit comments

Comments
 (0)