Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): ExoPlayer for Android #1691

Draft
wants to merge 43 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
61a2b50
feat!: FramePositionUpdater & TimerPositionUpdater
Gustl22 Oct 7, 2023
c0c40c2
Use ExoPlayer for Android
Gustl22 Apr 10, 2023
9393ef7
feat: new package audioplayers_android_exo
Gustl22 Oct 6, 2023
a718e78
revert changes in audioplayers_android
Gustl22 Oct 6, 2023
f4bcb3e
Link audioplayers exo
Gustl22 Oct 6, 2023
a51d52e
Basic functionality
Gustl22 Aug 29, 2023
441b518
remove exception for android < 0.5s
Gustl22 Oct 7, 2023
a266be2
adapt to timer updater
Gustl22 Oct 17, 2023
84fcb27
Try to use plugin override
Gustl22 Oct 18, 2023
db197c1
Merge remote-tracking branch 'upstream/main' into gustl22/349-configu…
Gustl22 Oct 18, 2023
edc2fa9
fix line length
Gustl22 Oct 18, 2023
00fd8a9
test with timer position updater, remove `hasPositionEvent`
Gustl22 Oct 20, 2023
98beba0
Update Test description
Gustl22 Oct 21, 2023
bd38fa5
Merge branch 'gustl22/349-configurable-position-updates' into gustl22…
Gustl22 Oct 21, 2023
e40ee05
Merge branch 'main' into gustl22/exoplayer
Gustl22 Nov 4, 2023
4268a3f
Update package dependencies
Gustl22 Nov 4, 2023
13bb543
remove handler
Gustl22 Nov 4, 2023
50de5e8
Enable multidex
Gustl22 Nov 4, 2023
6ff9488
Migrate to Media3
Gustl22 Nov 4, 2023
eb3cd78
Recreate Android folder
Gustl22 Nov 4, 2023
04f41c4
Update some values
Gustl22 Nov 5, 2023
4f0a982
enable multidex, update dependencies
Gustl22 Nov 5, 2023
be4656b
remove com.android.library
Gustl22 Nov 5, 2023
e9ff3ee
some changes
Gustl22 Nov 5, 2023
c8317b1
remove overhead code
Gustl22 Nov 5, 2023
dad3e47
Make playback work
Gustl22 Nov 5, 2023
8791a25
error message
Gustl22 Nov 5, 2023
de99adb
Player to PlayerWrapper
Gustl22 Nov 5, 2023
2317fb3
BytesSource
Gustl22 Nov 5, 2023
fccc802
Fix crash
Gustl22 Nov 5, 2023
a641cbe
Fix BytesSource
Gustl22 Nov 5, 2023
e018d5c
Format
Gustl22 Nov 5, 2023
9443ef8
Format
Gustl22 Nov 5, 2023
07358c0
Format
Gustl22 Nov 5, 2023
70fbd64
Attempt to set balance
Gustl22 Nov 5, 2023
d45dfdd
reapply channelmixingmatrix
Gustl22 Nov 6, 2023
b734922
rework audio channel processing
Gustl22 Nov 6, 2023
97f0377
Apply changes from audioplayers_android
Gustl22 Feb 8, 2024
808c023
Merge remote-tracking branch 'upstream/main' into gustl22/exoplayer
Gustl22 Feb 8, 2024
ea51103
Create custom AdaptiveChannelMixingAudioProcessor
Gustl22 Feb 8, 2024
6ffe41b
Merge branch 'main' into gustl22/exoplayer
Gustl22 Feb 12, 2025
121dc2e
apply changes
Gustl22 Feb 12, 2025
87bb355
update some files
Gustl22 Feb 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/audioplayers/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ publish_to: none

dependencies:
audioplayers: ^6.1.2
audioplayers_android_exo: ^0.0.1
collection: ^1.16.0
file_picker: ^8.0.3
flutter:
Expand Down

This file was deleted.

17 changes: 17 additions & 0 deletions packages/audioplayers_android_exo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*.iml
.DS_Store
.atom/
.idea
.packages
.dart_tool/
.pub/
build/
ios/.generated/
packages
.classpath
.project
.settings
.vscode
testing
.flutter-plugins-dependencies
flutter_export_environment.sh
10 changes: 10 additions & 0 deletions packages/audioplayers_android_exo/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: a0860f6e87ba4f9031bee4d6f56c08b970606bee
channel: dev

project_type: plugin
3 changes: 3 additions & 0 deletions packages/audioplayers_android_exo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

- **FEAT**: AudioPlayers for Android based on ExoPlayer
21 changes: 21 additions & 0 deletions packages/audioplayers_android_exo/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Luan Nico

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
22 changes: 22 additions & 0 deletions packages/audioplayers_android_exo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<p align="center">
<a href="https://pub.dev/packages/audioplayers">
<img alt="AudioPlayers" height="150px" src="https://raw.githubusercontent.com/bluefireteam/audioplayers/main/images/logo_ap_compact.svg">
</a>
</p>

---

# audioplayers_android_exo
<p>
<a title="Pub" href="https://pub.dev/packages/audioplayers_android_exo"><img src="https://img.shields.io/pub/v/audioplayers_android_exo.svg?style=popout&include_prereleases"/></a>
<a title="Build Status" href="https://github.com/bluefireteam/audioplayers/actions?query=workflow%3Abuild+branch%3Amain"><img src="https://github.com/bluefireteam/audioplayers/workflows/build/badge.svg?branch=main"/></a>
<a title="Discord" href="https://discord.gg/pxrBmy4"><img src="https://img.shields.io/discord/509714518008528896.svg"/></a>
<a title="Melos" href="https://github.com/invertase/melos"><img src="https://img.shields.io/badge/maintained%20with-melos-f700ff.svg"/></a>
</p>

The Android implementation of [`audioplayers`](https://pub.dev/packages/audioplayers).

## Usage

This package is [not endorsed](https://flutter.dev/docs/development/packages-and-plugins/developing-packages#endorsed-federated-plugin),
which means you can replace the default Android implementation of `audioplayers` with this package by adding `audioplayers_android_exo` to the apps `pubspec.yaml`.
1 change: 1 addition & 0 deletions packages/audioplayers_android_exo/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:flame_lint/analysis_options.yaml
12 changes: 12 additions & 0 deletions packages/audioplayers_android_exo/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures

/gradle
/gradlew
/gradlew.bat
83 changes: 83 additions & 0 deletions packages/audioplayers_android_exo/android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
group 'xyz.luan.audioplayers'
version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.7.10'
ext.coroutines_version = '1.6.4'

repositories {
google()
mavenCentral()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "de.mannodermaus.gradle.plugins:android-junit5:1.7.1.1"
}
}

rootProject.allprojects {
repositories {
google()
mavenCentral()
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'de.mannodermaus.android-junit5'

android {
compileSdk 33

// Conditional for compatibility with AGP <4.2.
if (project.android.hasProperty('namespace')) {
namespace 'xyz.luan.audioplayers'
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = '1.8'
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

defaultConfig {
minSdkVersion 16
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

lint {
disable 'InvalidPackage'
}
}

allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
}

dependencies {
implementation "androidx.core:core-ktx:1.9.0" // Do not pump unless dropping support for AGP7
implementation 'androidx.media3:media3-exoplayer:1.1.1'
implementation "androidx.media3:media3-exoplayer-dash:1.1.1"
implementation 'androidx.media3:media3-transformer:1.1.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.0'
testImplementation 'org.assertj:assertj-core:3.23.1'
}
repositories {
mavenCentral()
}
2 changes: 2 additions & 0 deletions packages/audioplayers_android_exo/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
1 change: 1 addition & 0 deletions packages/audioplayers_android_exo/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'audioplayers_android_exo'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest package="xyz.luan.audioplayers"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package xyz.luan.audioplayers

import android.annotation.SuppressLint
import android.media.AudioAttributes
import android.media.AudioAttributes.Builder
import android.media.AudioAttributes.CONTENT_TYPE_MUSIC
import android.media.AudioAttributes.USAGE_MEDIA
import android.media.AudioAttributes.USAGE_NOTIFICATION_RINGTONE
import android.media.AudioAttributes.USAGE_VOICE_COMMUNICATION
import android.media.AudioManager
import android.media.MediaPlayer
import android.os.Build
import androidx.annotation.RequiresApi
import java.util.*

data class AudioContextAndroid(
val isSpeakerphoneOn: Boolean,
val stayAwake: Boolean,
val contentType: Int,
val usageType: Int,
val audioFocus: Int,
val audioMode: Int,
) {
@SuppressLint("InlinedApi") // we are just using numerical constants
constructor() : this(
isSpeakerphoneOn = false,
stayAwake = false,
contentType = CONTENT_TYPE_MUSIC,
usageType = USAGE_MEDIA,
audioFocus = AudioManager.AUDIOFOCUS_GAIN,
audioMode = AudioManager.MODE_NORMAL,
)

fun setAttributesOnPlayer(player: MediaPlayer) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
player.setAudioAttributes(buildAttributes())
} else {
@Suppress("DEPRECATION")
player.setAudioStreamType(getStreamType())
}
}

@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
fun buildAttributes(): AudioAttributes {
return Builder()
.setUsage(usageType)
.setContentType(contentType)
.build()
}

@Deprecated("This is used for Android older than LOLLIPOP", replaceWith = ReplaceWith("buildAttributes"))
private fun getStreamType(): Int {
return when (usageType) {
USAGE_VOICE_COMMUNICATION -> AudioManager.STREAM_VOICE_CALL
USAGE_NOTIFICATION_RINGTONE -> AudioManager.STREAM_RING
else -> AudioManager.STREAM_MUSIC
}
}

override fun hashCode() = Objects.hash(isSpeakerphoneOn, stayAwake, contentType, usageType, audioFocus, audioMode)

override fun equals(other: Any?) = (other is AudioContextAndroid) &&
isSpeakerphoneOn == other.isSpeakerphoneOn &&
stayAwake == other.stayAwake &&
contentType == other.contentType &&
usageType == other.usageType &&
audioFocus == other.audioFocus &&
audioMode == other.audioMode
}
Loading