Skip to content

BarnabasSzabolcs/capacitor-play-audio-from-url

Repository files navigation

capacitor-play-audio-from-url

This capacitor plugin enables playing audio natively from a remote url, on web, android and ios.

Usage

import { PlayAudioFromUrl } from 'capacitor-play-audio-from-url'

PlayAudioFromUrl
    .play({ url: 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3' })
    .then(() => console.log('Audio played'))
    .catch((error) => console.error('Error playing audio (e.g. failed to load)', error));
// or
try {
    await PlayAudioFromUrl.play({url: 'https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3'})
    console.log('Audio played')
}catch (error) {
    console.error('Error playing audio (e.g. failed to load)', error)
}

Install

npm install capacitor-play-audio-from-url
npx cap sync

API

play(...)

play(options: PlayOptions) => Promise<void>

Plays an audio file from a given URL. In web mode, to avoid getting audio play rejected by mobile browsers when playing many audios, the audio sources are cached in an LRU cache with 256 entries.

Param Type Description
options PlayOptions - The options for playing the audio. Must include a url property with the URL of the audio file.

Interfaces

PlayOptions

Prop Type
url string

Development

To test, it is best to link it to a project using

npm install <path-to-the-project>

Then lots of npx cap sync, npx cap copy and building the apps for good measure.:)

About

A capacitor plugin to play audio from url.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published