Sonic Player
API

🎮 Player Functions

Expo Sonic provides a modern API to control audio playback. Below, functions are grouped by category: Playback, Session, and Metadata.


📦 Import

import { ExpoSonicPlayer } from "expo-sonic-ios-player";

▶️ Playback Methods

MethodSignatureDescription
play(options: AudioPlaybackOptions) => Promise<void>Start playing audio with options.
pause() => Promise<void>Pause the current playback.
resume() => Promise<void>Resume paused audio.
stop() => Promise<void>Stop and release the audio player.
seek(seconds: number) => Promise<void>Seek to a specific time in seconds.

AudioPlaybackOptions

interface AudioPlaybackOptions {
  url: string;
  title: string;
  artist: string;
  artwork?: string;
  duration?: number;
  album?: string;
  description?: string;
  isLive?: boolean;
  useSpatialAudio?: boolean; // ⚠️ Experimental
}
PropertyTypeRequiredDescription
urlstringAudio URL to play.
titlestringTrack title.
artiststringArtist name.
artworkstringArtwork image URL.
durationnumberDuration in seconds.
albumstringAlbum name.
descriptionstringTrack description.
isLivebooleanWhether the track is a live stream.
useSpatialAudioboolean⚠️ Experimental. May not work as expected.

🧠 Session Control

MethodSignatureDescription
toggleAmbientMode<T extends boolean>(enabled: T) => Promise<void>Enables or disables ambient audio mode (background).

🖼️ Metadata Management

MethodSignatureDescription
setMetaDataForCurrentTrack(metadata: TrackMetadata) => Promise<void>Update metadata shown on lock screen and control center.

TrackMetadata

interface TrackMetadata {
  title?: string;
  artist?: string;
  album?: string;
  artwork?: string;
  duration?: number;
}
PropertyTypeDescription
titlestringTrack title.
artiststringArtist name.
albumstringAlbum name.
artworkstringArtwork URL.
durationnumberDuration in seconds.

💡 Example

await ExpoSonicPlayer.play({
  url: "https://example.com/track.mp3",
  title: "Bloom",
  artist: "ODESZA",
  artwork: "https://example.com/cover.jpg",
  duration: 180,
  isLive: false,
});

await ExpoSonicPlayer.pause();
await ExpoSonicPlayer.resume();
await ExpoSonicPlayer.seek(90);
await ExpoSonicPlayer.stop();

await ExpoSonicPlayer.setMetaDataForCurrentTrack({
  title: "Bloom",
  artist: "ODESZA",
  artwork: "https://example.com/cover.jpg",
  duration: 180,
});

await ExpoSonicPlayer.toggleAmbientMode(true);