Skip to content

Commit 10ace57

Browse files
committed
[ogg_opus_player] refactor for android
1. refactor exoplayer to media3 2. support android 16k page size 3. example update
1 parent 7bd9850 commit 10ace57

File tree

31 files changed

+592
-227
lines changed

31 files changed

+592
-227
lines changed

packages/ogg_opus_player/android/build.gradle

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@ version '1.0'
55

66
buildscript {
77

8-
ext.kotlin_version = '1.6.10'
9-
ext.exoplayerVersion = '2.18.1'
8+
ext.kotlin_version = "2.1.0"
109

1110
repositories {
1211
google()
1312
mavenCentral()
1413
}
1514

1615
dependencies {
17-
classpath 'com.android.tools.build:gradle:7.1.2'
16+
classpath 'com.android.tools.build:gradle:8.9.1'
1817
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1918
}
2019
}
@@ -34,11 +33,11 @@ android {
3433

3534
// Bumping the plugin compileSdkVersion requires all clients of this plugin
3635
// to bump the version in their app.
37-
compileSdkVersion 31
36+
compileSdkVersion 36
3837

3938
// Bumping the plugin ndkVersion requires all clients of this plugin to bump
4039
// the version in their app and to download a newer version of the NDK.
41-
ndkVersion "21.1.6352462"
40+
ndkVersion android.ndkVersion
4241

4342
// Invoke the shared CMake build with the Android Gradle Plugin.
4443
externalNativeBuild {
@@ -56,24 +55,25 @@ android {
5655
}
5756

5857
compileOptions {
59-
sourceCompatibility JavaVersion.VERSION_1_8
60-
targetCompatibility JavaVersion.VERSION_1_8
58+
sourceCompatibility JavaVersion.VERSION_11
59+
targetCompatibility JavaVersion.VERSION_11
6160
}
6261

6362
kotlinOptions {
64-
jvmTarget = '1.8'
63+
jvmTarget = '11'
6564
}
6665

6766
sourceSets {
6867
main.java.srcDirs += 'src/main/kotlin'
6968
}
7069

7170
defaultConfig {
72-
minSdkVersion 21
71+
minSdkVersion 24
7372
}
7473
}
7574

7675
dependencies {
77-
implementation "com.google.android.exoplayer:exoplayer-core:${exoplayerVersion}"
78-
76+
def media3_version = "1.8.0"
77+
implementation "androidx.media3:media3-common:$media3_version"
78+
implementation "androidx.media3:media3-exoplayer:$media3_version"
7979
}

packages/ogg_opus_player/android/src/main/cpp/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,7 @@ target_link_libraries(ogg_opus_player_plugin
2626
lib_opusenc
2727
lib_opus
2828
lib_ogg
29-
log)
29+
log)
30+
31+
# Support Android 15 16k page size
32+
target_link_options(ogg_opus_player_plugin PRIVATE "-Wl,-z,max-page-size=16384")

packages/ogg_opus_player/android/src/main/kotlin/one/mixin/oggOpusPlayer/AudioPlayer.kt

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@ package one.mixin.oggOpusPlayer
22

33
import android.content.Context
44
import android.util.Log
5-
import com.google.android.exoplayer2.*
6-
import com.google.android.exoplayer2.audio.AudioAttributes
7-
import com.google.android.exoplayer2.source.ProgressiveMediaSource
8-
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector
9-
import com.google.android.exoplayer2.upstream.DefaultDataSource
5+
import androidx.media3.common.AudioAttributes
6+
import androidx.media3.common.C
7+
import androidx.media3.common.MediaItem
8+
import androidx.media3.common.PlaybackException
9+
import androidx.media3.common.Player
10+
import androidx.media3.common.util.UnstableApi
11+
import androidx.media3.datasource.DefaultDataSource
12+
import androidx.media3.exoplayer.ExoPlayer
13+
import androidx.media3.exoplayer.source.ProgressiveMediaSource
14+
import androidx.media3.exoplayer.trackselection.DefaultTrackSelector
15+
1016

1117
typealias OnPlayerStatusChangedCallback = (AudioPlayer) -> Unit
1218

@@ -16,6 +22,7 @@ enum class Status {
1622
Paused,
1723
}
1824

25+
@UnstableApi
1926
class AudioPlayer(
2027
context: Context,
2128
path: String,

packages/ogg_opus_player/android/src/main/kotlin/one/mixin/oggOpusPlayer/OggOpusPlayerPlugin.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package one.mixin.oggOpusPlayer
33
import android.content.Context
44
import android.content.pm.PackageManager
55
import android.os.SystemClock
6+
import androidx.annotation.OptIn
7+
import androidx.media3.common.util.UnstableApi
68
import io.flutter.embedding.engine.plugins.FlutterPlugin
79
import io.flutter.plugin.common.MethodCall
810
import io.flutter.plugin.common.MethodChannel
@@ -36,6 +38,7 @@ class OggOpusPlayerPlugin : FlutterPlugin, MethodCallHandler {
3638
channel.setMethodCallHandler(this)
3739
}
3840

41+
@OptIn(UnstableApi::class)
3942
override fun onMethodCall(call: MethodCall, result: Result) {
4043
when (call.method) {
4144
"create" -> {
@@ -135,6 +138,7 @@ class OggOpusPlayerPlugin : FlutterPlugin, MethodCallHandler {
135138
}
136139
}
137140

141+
@UnstableApi
138142
private fun handlePlayerStateChanged(id: Int, player: AudioPlayer) {
139143
channel.invokeMethod(
140144
"onPlayerStateChanged", mapOf(
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: "ac4e799d237041cf905519190471f657b657155a"
8+
channel: "stable"
9+
10+
project_type: app
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: ac4e799d237041cf905519190471f657b657155a
17+
base_revision: ac4e799d237041cf905519190471f657b657155a
18+
- platform: android
19+
create_revision: ac4e799d237041cf905519190471f657b657155a
20+
base_revision: ac4e799d237041cf905519190471f657b657155a
21+
- platform: ios
22+
create_revision: ac4e799d237041cf905519190471f657b657155a
23+
base_revision: ac4e799d237041cf905519190471f657b657155a
24+
- platform: linux
25+
create_revision: ac4e799d237041cf905519190471f657b657155a
26+
base_revision: ac4e799d237041cf905519190471f657b657155a
27+
- platform: macos
28+
create_revision: ac4e799d237041cf905519190471f657b657155a
29+
base_revision: ac4e799d237041cf905519190471f657b657155a
30+
- platform: web
31+
create_revision: ac4e799d237041cf905519190471f657b657155a
32+
base_revision: ac4e799d237041cf905519190471f657b657155a
33+
- platform: windows
34+
create_revision: ac4e799d237041cf905519190471f657b657155a
35+
base_revision: ac4e799d237041cf905519190471f657b657155a
36+
37+
# User provided section
38+
39+
# List of Local paths (relative to this file) that should be
40+
# ignored by the migrate tool.
41+
#
42+
# Files that are not part of the templates will be ignored by default.
43+
unmanaged_files:
44+
- 'lib/main.dart'
45+
- 'ios/Runner.xcodeproj/project.pbxproj'

packages/ogg_opus_player/example/android/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ gradle-wrapper.jar
55
/gradlew.bat
66
/local.properties
77
GeneratedPluginRegistrant.java
8+
.cxx/
89

910
# Remember to never publicly share your keystore.
10-
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11+
# See https://flutter.dev/to/reference-keystore
1112
key.properties
1213
**/*.keystore
1314
**/*.jks

packages/ogg_opus_player/example/android/app/build.gradle

Lines changed: 0 additions & 71 deletions
This file was deleted.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
plugins {
2+
id("com.android.application")
3+
id("kotlin-android")
4+
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
5+
id("dev.flutter.flutter-gradle-plugin")
6+
}
7+
8+
android {
9+
namespace = "com.example.ogg_opus_player_example"
10+
compileSdk = flutter.compileSdkVersion
11+
ndkVersion = flutter.ndkVersion
12+
13+
compileOptions {
14+
sourceCompatibility = JavaVersion.VERSION_11
15+
targetCompatibility = JavaVersion.VERSION_11
16+
}
17+
18+
kotlinOptions {
19+
jvmTarget = JavaVersion.VERSION_11.toString()
20+
}
21+
22+
defaultConfig {
23+
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
24+
applicationId = "com.example.ogg_opus_player_example"
25+
// You can update the following values to match your application needs.
26+
// For more information, see: https://flutter.dev/to/review-gradle-config.
27+
minSdk = flutter.minSdkVersion
28+
targetSdk = flutter.targetSdkVersion
29+
versionCode = flutter.versionCode
30+
versionName = flutter.versionName
31+
}
32+
33+
buildTypes {
34+
release {
35+
// TODO: Add your own signing config for the release build.
36+
// Signing with the debug keys for now, so `flutter run --release` works.
37+
signingConfig = signingConfigs.getByName("debug")
38+
}
39+
}
40+
}
41+
42+
flutter {
43+
source = "../.."
44+
}

packages/ogg_opus_player/example/android/app/src/debug/AndroidManifest.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.example.ogg_opus_player_example">
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
32
<!-- The INTERNET permission is required for development. Specifically,
43
the Flutter tool needs it to communicate with the running application
54
to allow setting breakpoints, to provide hot reload, etc.

packages/ogg_opus_player/example/android/app/src/main/AndroidManifest.xml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.example.ogg_opus_player_example">
3-
<application
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
2+
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
3+
<application
44
android:label="ogg_opus_player_example"
5+
android:name="${applicationName}"
56
android:icon="@mipmap/ic_launcher">
67
<activity
78
android:name=".MainActivity"
89
android:exported="true"
910
android:launchMode="singleTop"
11+
android:taskAffinity=""
1012
android:theme="@style/LaunchTheme"
1113
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
1214
android:hardwareAccelerated="true"
@@ -30,4 +32,15 @@
3032
android:name="flutterEmbedding"
3133
android:value="2" />
3234
</application>
35+
<!-- Required to query activities that can process text, see:
36+
https://developer.android.com/training/package-visibility and
37+
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
38+
39+
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
40+
<queries>
41+
<intent>
42+
<action android:name="android.intent.action.PROCESS_TEXT"/>
43+
<data android:mimeType="text/plain"/>
44+
</intent>
45+
</queries>
3346
</manifest>

0 commit comments

Comments
 (0)