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

chore: sync up main #7

Merged
merged 10 commits into from
Jul 24, 2023
Merged
18 changes: 9 additions & 9 deletions docs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6548,19 +6548,19 @@ semver@7.0.0:
integrity sha512-+GB6zVA9LWh6zovYQLALHwv5rb2PHGlJi3lfiqIHxR0uuwCgefcOJc59v9fv1w8GbStwxuuqqAjI9NMAOOgq1A==

semver@^5.4.1:
version "5.7.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==
version "5.7.2"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.2.tgz#48d55db737c3287cd4835e17fa13feace1c41ef8"
integrity sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==

semver@^6.0.0, semver@^6.1.1, semver@^6.1.2, semver@^6.2.0, semver@^6.3.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
version "6.3.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4"
integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==

semver@^7.3.2, semver@^7.3.4, semver@^7.3.5:
version "7.3.7"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.7.tgz#12c5b649afdbf9049707796e22a4028814ce523f"
integrity sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==
version "7.5.4"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e"
integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==
dependencies:
lru-cache "^6.0.0"

Expand Down
2 changes: 2 additions & 0 deletions example/android/scripts/logs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ function monitor_logs {
adb logcat --pid="$1" &
LOGCAT_PID=$!

trap 'echo "Received SIGINT, cleaning up..."; kill $LOGCAT_PID; exit 1' SIGINT

while adb shell "pidof -s $PACKAGE_NAME >/dev/null"; do
sleep 1
done
Expand Down
2 changes: 1 addition & 1 deletion example/ios/.ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.0
3.2.0
1 change: 1 addition & 0 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ target 'example' do
__apply_Xcode_12_5_M1_post_install_workaround(installer)
end
end

3 changes: 2 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"android:install-release": "RD=android/app/build/outputs/bundle/release && (rm $RD/app.apks || true) && bundletool build-apks --bundle=$RD/app-release.aab --output=$RD/app.apks && (adb uninstall com.example || true) && bundletool install-apks --apks=$RD/app.apks",
"android:logs": "android/scripts/logs",
"ios": "react-native run-ios",
"ios:sim": "react-native run-ios --simulator=\"iPhone\"",
"ios:ide": "open ios/*.xcworkspace/",
"windows": "react-native run-windows",
"start": "react-native start",
Expand All @@ -24,7 +25,7 @@
"dependencies": {
"@react-native-community/slider": "^4.4.2",
"react": "18.2.0",
"react-native": "0.71.8",
"react-native": "0.71.12",
"react-native-windows": "^0.65.0-0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion example/src/components/TrackInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const TrackInfo: React.FC<{
}> = ({ track }) => {
return (
<View style={styles.container}>
<Image style={styles.artwork} source={{ uri: `${track?.artwork}` }} />
<Image style={styles.artwork} source={{ uri: track?.artwork }} />
<Text style={styles.titleText}>{track?.title}</Text>
<Text style={styles.artistText}>{track?.artist}</Text>
</View>
Expand Down
397 changes: 230 additions & 167 deletions example/yarn.lock

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions src/hooks/useProgress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ import { Event } from '../constants';
import type { Progress } from '../interfaces';
import { useTrackPlayerEvents } from './useTrackPlayerEvents';

const INITIAL_STATE = {
position: 0,
duration: 0,
buffered: 0,
};

/**
* Poll for track progress for the given interval (in miliseconds)
* @param updateInterval - ms interval
*/
export function useProgress(updateInterval = 1000) {
const INITIAL = {
position: 0,
duration: 0,
buffered: 0,
};
const [state, setState] = useState<Progress>(INITIAL);
const [state, setState] = useState<Progress>(INITIAL_STATE);

useTrackPlayerEvents([Event.PlaybackActiveTrackChanged], () => {
setState(INITIAL);
setState(INITIAL_STATE);
});

useEffect(() => {
Expand Down
11 changes: 8 additions & 3 deletions src/interfaces/Track.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { PitchAlgorithm, TrackType } from '../constants';
import { ResourceObject } from './ResourceObject';
import type { TrackMetadataBase } from './TrackMetadataBase';
import type { ResourceObject } from './ResourceObject';
import type { TrackType, PitchAlgorithm } from '../constants';

export interface Track extends TrackMetadataBase {
url: string | ResourceObject;
url: string;
type?: TrackType;
/** The user agent HTTP header */
userAgent?: string;
Expand All @@ -16,3 +16,8 @@ export interface Track extends TrackMetadataBase {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
}

export type AddTrack = Track & {
url: string | ResourceObject;
artwork?: string | ResourceObject;
};
3 changes: 1 addition & 2 deletions src/interfaces/TrackMetadataBase.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { ResourceObject } from './ResourceObject';
import type { RatingType } from '../constants';

export interface TrackMetadataBase {
Expand All @@ -11,7 +10,7 @@ export interface TrackMetadataBase {
/** The track duration in seconds */
duration?: number;
/** The track artwork */
artwork?: string | ResourceObject;
artwork?: string;
/** track description */
description?: string;
/** The track genre */
Expand Down
110 changes: 51 additions & 59 deletions src/trackPlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { default as resolveAssetSource } from 'react-native/Libraries/Image/reso

import { Event, RepeatMode, State } from './constants';
import type {
AddTrack,
EventPayloadByEvent,
NowPlayingMetadata,
PlaybackState,
Expand All @@ -29,9 +30,18 @@ const emitter =

// MARK: - Helpers

function resolveImportedPath(path?: number | string) {
if (!path) return undefined;
return resolveAssetSource(path) || path;
function resolveImportedAssetOrPath(pathOrAsset: string | number | undefined) {
return pathOrAsset === undefined
? undefined
: typeof pathOrAsset === 'string'
? pathOrAsset
: resolveImportedAsset(pathOrAsset)?.uri;
}

function resolveImportedAsset(id?: number) {
return id
? (resolveAssetSource(id) as { uri: string } | null) ?? undefined
: undefined;
}

// MARK: - General API
Expand Down Expand Up @@ -90,7 +100,7 @@ export function isServiceRunning(): Promise<boolean> {
* By default the tracks will be added to the end of the queue.
*/
export async function add(
tracks: Track[],
tracks: AddTrack[],
insertBeforeIndex?: number
): Promise<number | void>;
/**
Expand All @@ -101,32 +111,23 @@ export async function add(
* By default the track will be added to the end of the queue.
*/
export async function add(
track: Track,
track: AddTrack,
insertBeforeIndex?: number
): Promise<number | void>;
export async function add(
tracks: Track | Track[],
tracks: AddTrack | AddTrack[],
insertBeforeIndex = -1
): Promise<number | void> {
// Clone the array before modifying it
if (Array.isArray(tracks)) {
tracks = [...tracks];
} else {
tracks = [tracks];
}

if (tracks.length < 1) return;

for (let i = 0; i < tracks.length; i++) {
// Clone the object before modifying it
tracks[i] = { ...tracks[i] };

// Resolve the URLs
tracks[i].url = resolveImportedPath(tracks[i].url);
tracks[i].artwork = resolveImportedPath(tracks[i].artwork);
}

return TrackPlayer.add(tracks, insertBeforeIndex);
const resolvedTracks = (Array.isArray(tracks) ? tracks : [tracks]).map(
(track) => ({
...track,
url: resolveImportedAssetOrPath(track.url),
artwork: resolveImportedAssetOrPath(track.artwork),
})
);
return resolvedTracks.length < 1
? undefined
: TrackPlayer.add(resolvedTracks, insertBeforeIndex);
}

/**
Expand Down Expand Up @@ -222,26 +223,23 @@ export async function updateOptions({
alwaysPauseOnInterruption,
...options
}: UpdateOptions = {}): Promise<void> {
// Handle deprecated alwaysPauseOnInterruption option:
if (
alwaysPauseOnInterruption !== undefined &&
!(options.android && 'alwaysPauseOnInterruption' in options.android)
) {
if (!options.android) options.android = {};
options.android.alwaysPauseOnInterruption = alwaysPauseOnInterruption;
}

// Resolve the asset for each icon
options.icon = resolveImportedPath(options.icon);
options.playIcon = resolveImportedPath(options.playIcon);
options.pauseIcon = resolveImportedPath(options.pauseIcon);
options.stopIcon = resolveImportedPath(options.stopIcon);
options.previousIcon = resolveImportedPath(options.previousIcon);
options.nextIcon = resolveImportedPath(options.nextIcon);
options.rewindIcon = resolveImportedPath(options.rewindIcon);
options.forwardIcon = resolveImportedPath(options.forwardIcon);

return TrackPlayer.updateOptions(options);
return TrackPlayer.updateOptions({
android: {
// Handle deprecated alwaysPauseOnInterruption option:
alwaysPauseOnInterruption:
options.android?.alwaysPauseOnInterruption ?? alwaysPauseOnInterruption,
...options.android,
},
icon: resolveImportedAsset(options.icon),
playIcon: resolveImportedAsset(options.playIcon),
pauseIcon: resolveImportedAsset(options.pauseIcon),
stopIcon: resolveImportedAsset(options.stopIcon),
previousIcon: resolveImportedAsset(options.previousIcon),
nextIcon: resolveImportedAsset(options.nextIcon),
rewindIcon: resolveImportedAsset(options.rewindIcon),
forwardIcon: resolveImportedAsset(options.forwardIcon),
...options,
});
}

/**
Expand All @@ -255,13 +253,10 @@ export async function updateMetadataForTrack(
trackIndex: number,
metadata: TrackMetadataBase
): Promise<void> {
// Clone the object before modifying it
metadata = Object.assign({}, metadata);

// Resolve the artwork URL
metadata.artwork = resolveImportedPath(metadata.artwork);

return TrackPlayer.updateMetadataForTrack(trackIndex, metadata);
return TrackPlayer.updateMetadataForTrack(trackIndex, {
...metadata,
artwork: resolveImportedAssetOrPath(metadata.artwork),
});
}

/**
Expand All @@ -276,13 +271,10 @@ export function clearNowPlayingMetadata(): Promise<void> {
export function updateNowPlayingMetadata(
metadata: NowPlayingMetadata
): Promise<void> {
// Clone the object before modifying it
metadata = Object.assign({}, metadata);

// Resolve the artwork URL
metadata.artwork = resolveImportedPath(metadata.artwork);

return TrackPlayer.updateNowPlayingMetadata(metadata);
return TrackPlayer.updateNowPlayingMetadata({
...metadata,
artwork: resolveImportedAssetOrPath(metadata.artwork),
});
}

// MARK: - Player API
Expand Down
24 changes: 12 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6027,19 +6027,19 @@ scheduler@^0.20.1, scheduler@^0.20.2:
object-assign "^4.1.1"

"semver@2 || 3 || 4 || 5", semver@^5.3.0, semver@^5.4.1, semver@^5.5.0, semver@^5.6.0:
version "5.7.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==
version "5.7.2"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.2.tgz#48d55db737c3287cd4835e17fa13feace1c41ef8"
integrity sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==

semver@^6.0.0, semver@^6.1.1, semver@^6.1.2, semver@^6.3.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
version "6.3.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4"
integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==

semver@^7.3.2, semver@^7.3.4, semver@^7.3.7:
version "7.3.8"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.8.tgz#07a78feafb3f7b32347d725e33de7e2a2df67798"
integrity sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==
version "7.5.4"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e"
integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==
dependencies:
lru-cache "^6.0.0"

Expand Down Expand Up @@ -6867,9 +6867,9 @@ which@^2.0.1:
isexe "^2.0.0"

word-wrap@^1.0.3, word-wrap@^1.2.3:
version "1.2.3"
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c"
integrity sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==
version "1.2.4"
resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.4.tgz#cb4b50ec9aca570abd1f52f33cd45b6c61739a9f"
integrity sha512-2V81OA4ugVo5pRo46hAoD2ivUJx8jXmWXfUkY4KFNw0hEptvN0QfH3K4nHiwzGeKl5rFKedV48QVoqYavy4YpA==

wordwrap@^1.0.0:
version "1.0.0"
Expand Down