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: volume fade in/out #2121

Closed
wants to merge 80 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
d99812b
feat: frankenstein HeadlessJsTaskService + MediaBrowserServiceCompat
lovegaoshi Jun 15, 2023
e90b886
feat: android auto
Jun 15, 2023
04c27d0
feat: b4 implementing setCommand
lovegaoshi Jun 18, 2023
2cfa59a
feat: android auto
lovegaoshi Jun 20, 2023
8734a43
Create automotive_app_desc.xml
lovegaoshi Jun 20, 2023
ba3afe4
Update AndroidManifest.xml
lovegaoshi Jun 20, 2023
0a3f2a1
Revert "Update AndroidManifest.xml"
lovegaoshi Jun 20, 2023
e0a9246
Update build.gradle
lovegaoshi Jun 21, 2023
6df90ac
Update build.gradle
lovegaoshi Jun 26, 2023
b28f50d
Merge branch 'dev-android-auto' of https://github.com/lovegaoshi/reac…
lovegaoshi Jun 27, 2023
1977e7d
Update build.gradle
lovegaoshi Jun 27, 2023
19086af
fix: revert changes in targetSdkVersion
lovegaoshi Jun 27, 2023
2a6e765
chore: resolve
Jul 10, 2023
ed2f430
Merge branch 'doublesymmetry-main' into dev-android-auto
Jul 10, 2023
77655a8
Update build.gradle
lovegaoshi Jul 10, 2023
9d0589e
feat: AA MediaSession.Callback test
lovegaoshi Jul 12, 2023
e256990
feat: emit MediaSession.Callback
Jul 12, 2023
e7d2a5a
feat: loadMediaItems
Jul 12, 2023
0cbfe06
fix: KA mediaSession.Callback
lovegaoshi Jul 13, 2023
d99c436
feat: loadBrowseTree
Jul 13, 2023
329562a
feat: loadBrowseTree
Jul 13, 2023
da4a181
feat: AA content hierarchy
lovegaoshi Jul 14, 2023
ff4c15b
Merge pull request #5 from lovegaoshi/dev-android-auto
lovegaoshi Jul 14, 2023
29a43fb
feat: RemoteSkip
lovegaoshi Jul 17, 2023
66156cd
Merge pull request #6 from lovegaoshi/dev-android-auto
lovegaoshi Jul 17, 2023
325a23d
Update build.gradle
lovegaoshi Jul 19, 2023
d882a0a
Update build.gradle
lovegaoshi Jul 19, 2023
932f299
fix: android only remote services
lovegaoshi Jul 20, 2023
9a30009
fix: refresh browseTree content
lovegaoshi Jul 24, 2023
333d7a4
Merge pull request #7 from doublesymmetry/main
lovegaoshi Jul 24, 2023
b739a13
feat: AA content style
lovegaoshi Jul 25, 2023
95e0927
Merge branch 'dev-android-auto-PR' into dev-android-auto
lovegaoshi Jul 25, 2023
de77707
fix: cycling dependency
lovegaoshi Jul 25, 2023
7cfdf0b
Merge branch 'dev-android-auto' of https://github.com/lovegaoshi/reac…
lovegaoshi Jul 25, 2023
5643a83
FIX: MERGE CONFLICT
lovegaoshi Jul 25, 2023
5971065
feat: open UI when create service
lovegaoshi Jul 28, 2023
aee71eb
Merge branch 'main' of https://github.com/doublesymmetry/react-native…
lovegaoshi Aug 13, 2023
e2f95d0
fix: sync up KotlinAudio
lovegaoshi Aug 13, 2023
63f6e33
Merge branch 'main' of https://github.com/doublesymmetry/react-native…
lovegaoshi Aug 19, 2023
9cd6ebb
chore: upgrade KA
lovegaoshi Aug 19, 2023
62ea3ec
feat(musicmodule): adds support for grouping lists with subheading
schoetty Aug 23, 2023
1a96713
Merge pull request #11 from schoetty/dev-android-auto
lovegaoshi Aug 24, 2023
58f64ca
feat: startActivity permission
lovegaoshi Aug 24, 2023
f8778a9
chore: grouping list example
lovegaoshi Aug 24, 2023
1a5ed5c
fix(example): startActivity permission
lovegaoshi Aug 24, 2023
ebd4aca
Merge pull request #12 from doublesymmetry/main
lovegaoshi Aug 26, 2023
f3c9c78
fix(example): AA declarations
lovegaoshi Aug 26, 2023
430bc66
fix: linting
lovegaoshi Aug 26, 2023
35c42e0
Update build.gradle
lovegaoshi Aug 26, 2023
014141c
fix: linting
lovegaoshi Aug 29, 2023
4e2730d
feat: remoteBrowse
lovegaoshi Aug 29, 2023
ad589ec
Merge pull request #14 from lovegaoshi/dev-android-auto
lovegaoshi Aug 29, 2023
bf0062b
fix: lint
lovegaoshi Aug 29, 2023
1ee2891
Merge pull request #15 from lovegaoshi/dev-android-auto
lovegaoshi Aug 29, 2023
077e500
feat: custom actions
lovegaoshi Sep 4, 2023
5f585b7
feat: fade inout
Sep 8, 2023
d211dd7
feat: fade volume
Sep 8, 2023
0d71633
feat: fade volume
lovegaoshi Sep 9, 2023
a3075c7
feat: fade volume
lovegaoshi Sep 9, 2023
682499c
fix: lint
lovegaoshi Sep 9, 2023
09ff3d3
refactor: fade wrapper functions
lovegaoshi Sep 10, 2023
6b41c99
refactor: refactor: fade wrapper functions
lovegaoshi Sep 10, 2023
ae895ad
fix: lint
lovegaoshi Sep 11, 2023
e224bae
Merge branch 'APM' into dev-fadeinout
lovegaoshi Sep 11, 2023
542dab3
Revert "Merge branch 'APM' into dev-fadeinout"
lovegaoshi Sep 11, 2023
30db29a
Merge branch 'main' into dev-fadeinout
lovegaoshi Sep 19, 2023
fc5027b
Merge branch 'main' into dev-fadeinout
lovegaoshi Oct 30, 2023
a667901
Update prepare-commit-msg
lovegaoshi Oct 30, 2023
19eb3b3
Merge branch 'doublesymmetry:main' into dev-fadeinout
lovegaoshi Oct 31, 2023
06fdc4f
Merge branch 'main' of https://github.com/doublesymmetry/react-native…
lovegaoshi Feb 3, 2024
b79de00
fix: fading default
lovegaoshi Feb 2, 2024
0e7cd2f
fix: fading default
lovegaoshi Feb 3, 2024
be5c11c
Merge branch 'main' of https://github.com/lovegaoshi/react-native-tra…
lovegaoshi Mar 13, 2024
1f4fd3b
Merge branch 'main' of https://github.com/lovegaoshi/react-native-tra…
lovegaoshi Mar 14, 2024
b017c9d
style: lint
lovegaoshi Mar 14, 2024
2cefef7
feat: sync up main
lovegaoshi Mar 25, 2024
9a41bd3
Merge branch 'main' of https://github.com/lovegaoshi/react-native-tra…
lovegaoshi Mar 27, 2024
6185bc1
Merge branch 'main' of https://github.com/lovegaoshi/react-native-tra…
lovegaoshi Apr 19, 2024
f161167
Merge branch 'doublesymmetry:main' into dev-fadeinout
lovegaoshi May 3, 2024
3a5c46d
style: prettier
lovegaoshi May 3, 2024
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
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ repositories {
}

dependencies {
implementation 'com.github.doublesymmetry:kotlinaudio:v2.1.0'
implementation 'com.github.lovegaoshi:KotlinAudio:v2.0.0-fade5'
// used when building against local maven
// implementation "com.github.doublesymmetry:kotlin-audio:2.1.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class MusicEvents(private val reactContext: ReactContext) : BroadcastReceiver()
const val PLAYBACK_METADATA = "playback-metadata-received"
const val PLAYBACK_PROGRESS_UPDATED = "playback-progress-updated"
const val PLAYBACK_ERROR = "playback-error"
const val PLAYBACK_ANIMATED_VOLUME_CHANGED = "playback-animated-volume-changed"

// Metadata Events
const val METADATA_CHAPTER_RECEIVED = "metadata-chapter-received"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,4 +626,39 @@ class MusicModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaM
if (verifyServiceBoundOrReject(callback)) return@launch
callback.resolve(Arguments.fromBundle(musicService.getPlayerStateBundle(musicService.state)))
}

@ReactMethod
fun setAnimatedVolume(volume: Float = 1f, duration: Int = 0, interval: Int = 20, msg: String = "", callback: Promise) = scope.launch {
if (verifyServiceBoundOrReject(callback)) return@launch
musicService.setAnimatedVolume(volume, duration.toLong(), interval.toLong(), msg).await()
callback.resolve(null)
}

@ReactMethod
fun fadeOutPause(duration: Int = 0, interval: Int = 20, callback: Promise) = scope.launch {
if (verifyServiceBoundOrReject(callback)) return@launch
musicService.fadeOutPause(duration.toLong(), interval.toLong())
callback.resolve(null)
}

@ReactMethod
fun fadeOutNext(duration: Int = 0, interval: Int = 20, toVolume: Float = 1f, callback: Promise) = scope.launch {
if (verifyServiceBoundOrReject(callback)) return@launch
musicService.fadeOutNext(duration.toLong(), interval.toLong(), toVolume)
callback.resolve(null)
}

@ReactMethod
fun fadeOutPrevious(duration: Int = 0, interval: Int = 20, toVolume: Float = 1f, callback: Promise) = scope.launch {
if (verifyServiceBoundOrReject(callback)) return@launch
musicService.fadeOutPrevious(duration.toLong(), interval.toLong(), toVolume)
callback.resolve(null)
}

@ReactMethod
fun fadeOutJump(index: Int, duration: Int = 0, interval: Int = 20, toVolume: Float = 1f, callback: Promise) = scope.launch {
if (verifyServiceBoundOrReject(callback)) return@launch
musicService.fadeOutJump(index, duration.toLong(), interval.toLong(), toVolume)
callback.resolve(null)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,44 @@ class MusicService : HeadlessJsTaskService() {
player.volume = value
}

@MainThread
fun setAnimatedVolume(value: Float, duration: Long = 500L, interval: Long = 20L, emitEventMsg: String = ""): Deferred<Unit> {
val eventMsgBundle = Bundle()
eventMsgBundle.putString(DATA_KEY, emitEventMsg)
return player.fadeVolume(value, duration, interval) {
emit(
MusicEvents.PLAYBACK_ANIMATED_VOLUME_CHANGED,
eventMsgBundle
)
}
}

fun fadeOutPause (duration: Long = 500L, interval: Long = 20L) {
player.fadeVolume(0f, duration, interval) {
player.pause()
}
}

fun fadeOutNext (duration: Long = 500L, interval: Long = 20L, toVolume: Float = 1f) {
player.fadeVolume(0f, duration, interval) {
player.next()
player.fadeVolume(toVolume, duration, interval)
}
}

fun fadeOutPrevious (duration: Long = 500L, interval: Long = 20L, toVolume: Float = 1f) {
player.fadeVolume(0f, duration, interval) {
player.previous()
player.fadeVolume(toVolume, duration, interval)
}
}

fun fadeOutJump (index: Int, duration: Long = 500L, interval: Long = 20L, toVolume: Float = 1f) {
player.fadeVolume(0f, duration, interval) {
player.jumpToItem(index)
player.fadeVolume(toVolume, duration, interval)
}
}
@MainThread
fun getDurationInSeconds(): Double = player.duration.toSeconds()

Expand Down
13 changes: 12 additions & 1 deletion example/src/components/PlayPauseButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,24 @@ import FontAwesome6 from 'react-native-vector-icons/FontAwesome6';
export const PlayPauseButton: React.FC = () => {
const { playing, bufferingDuringPlay } = useIsPlaying();

const onFadeOutPause = () => {
TrackPlayer.fadeOutPause();
};

const onFadeInPlay = () => {
TrackPlayer.play();
TrackPlayer.setAnimatedVolume({
volume: 1,
});
};

return (
<View style={styles.container}>
{bufferingDuringPlay ? (
<ActivityIndicator />
) : (
<TouchableWithoutFeedback
onPress={playing ? TrackPlayer.pause : TrackPlayer.play}
onPress={playing ? onFadeOutPause : onFadeInPlay}
>
<FontAwesome6
name={playing ? 'pause' : 'play'}
Expand Down
4 changes: 2 additions & 2 deletions example/src/components/PlayerControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import FontAwesome6 from 'react-native-vector-icons/FontAwesome6';
import { PlaybackError } from './PlaybackError';
import { PlayPauseButton } from './PlayPauseButton';

const performSkipToNext = () => TrackPlayer.skipToNext();
const performSkipToPrevious = () => TrackPlayer.skipToPrevious();
const performSkipToNext = () => TrackPlayer.fadeOutNext();
const performSkipToPrevious = () => TrackPlayer.fadeOutPrevious();

export const PlayerControls: React.FC = () => {
const playback = usePlaybackState();
Expand Down
5 changes: 5 additions & 0 deletions example/src/constant.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export enum FadeEvent {
FadePause = 'FadePause',
FadeNext = 'FadeNext',
FadePrevious = 'FadePrevious',
}
13 changes: 10 additions & 3 deletions example/src/services/PlaybackService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@ import TrackPlayer, { Event } from 'react-native-track-player';
export async function PlaybackService() {
TrackPlayer.addEventListener(Event.RemotePause, () => {
console.log('Event.RemotePause');
TrackPlayer.pause();
TrackPlayer.fadeOutPause();
});

TrackPlayer.addEventListener(Event.RemotePlay, () => {
console.log('Event.RemotePlay');
TrackPlayer.play();
TrackPlayer.setAnimatedVolume({
volume: 1,
});
});

TrackPlayer.addEventListener(Event.RemoteNext, () => {
console.log('Event.RemoteNext');
TrackPlayer.skipToNext();
TrackPlayer.fadeOutNext();
});

TrackPlayer.addEventListener(Event.RemotePrevious, () => {
console.log('Event.RemotePrevious');
TrackPlayer.skipToPrevious();
TrackPlayer.fadeOutPrevious();
});

TrackPlayer.addEventListener(Event.RemoteJumpForward, async (event) => {
Expand Down Expand Up @@ -76,6 +79,10 @@ export async function PlaybackService() {
console.log('Event.MetadataCommonReceived', event);
});

TrackPlayer.addEventListener(Event.PlaybackAnimatedVolumeChanged, (event) => {
console.log('Event.PlaybackAnimatedVolumeChanged', event.data);
});

TrackPlayer.addEventListener(Event.PlaybackProgressUpdated, (event) => {
console.log('Event.PlaybackProgressUpdated', event);
});
Expand Down
2 changes: 2 additions & 0 deletions src/constants/Event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export enum Event {
PlaybackState = 'playback-state',
/** Fired when a playback error occurs. */
PlaybackError = 'playback-error',
/** (Android Only) Fired when animated volume completed changing. */
PlaybackAnimatedVolumeChanged = 'playback-animated-volume-changed',
/** Fired after playback has paused due to the queue having reached the end. */
PlaybackQueueEnded = 'playback-queue-ended',
/**
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/events/EventPayloadByEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type { RemotePlaySearchEvent } from './RemotePlaySearchEvent';
import type { RemoteSeekEvent } from './RemoteSeekEvent';
import type { RemoteSetRatingEvent } from './RemoteSetRatingEvent';
import type { RemoteSkipEvent } from './RemoteSkipEvent';
import type { PlaybackAnimatedVolumeChangedEvent } from './PlaybackAnimatedVolumeChangedEvent';

export type EventPayloadByEvent = {
[Event.PlayerError]: PlayerErrorEvent;
Expand Down Expand Up @@ -46,6 +47,7 @@ export type EventPayloadByEvent = {
[Event.RemoteLike]: never;
[Event.RemoteDislike]: never;
[Event.RemoteBookmark]: never;
[Event.PlaybackAnimatedVolumeChanged]: PlaybackAnimatedVolumeChangedEvent;
[Event.MetadataChapterReceived]: AudioMetadataReceivedEvent;
[Event.MetadataTimedReceived]: AudioMetadataReceivedEvent;
[Event.MetadataCommonReceived]: AudioCommonMetadataReceivedEvent;
Expand Down
4 changes: 4 additions & 0 deletions src/interfaces/events/PlaybackAnimatedVolumeChangedEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface PlaybackAnimatedVolumeChangedEvent {
/** the event message */
data: string;
}
Loading
Loading