apache / apache/cordova-plugin-media

Feature Request: Specify custom Media ID in the JS API (will send simple PR if approved)

Open
#302 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
391
Forks
762
PR merge metrics
No merged PRs in 30d

Description

# Feature Request

## Motivation Behind Feature
When webview restarts, e.g. due to battery saving feature when app is in background, it could access previously started sound -and control it.

Also when developing in live reload the link to file is lost.

## Feature Description
I play a long MP3, UUID is generated for the MP3 and status update callbacks are connected to the app. I turn off the screen and put my phone away. The sound keeps playing.

After five minutes I unlock the screen, but the webview was killed to save battery and now has reloaded. Unfortunately it can no more acquire the pointer to the MP3 file, thus it cannot control its playing and it plays on its own now and status updates are not transmitted to the app.

If I was able to specify a fixed ID instead of UUID, I could reacquire the handle, because internally existing Media object is returned if exists both for Android and iOS.

**The code change would be easy**: To allow custom id assignment in this function, e.g. to pass `[id,src]` instead of `src` and use that `id`. Will be happy to send a PR if you agree to implement.
https://github.com/apache/cordova-plugin-media/blob/eb99c859ee8f5743c36a4355f4a71d43ce146444/www/Media.js#L42-L53

## Alternatives or Workarounds
It would be also interesting to be able to list currently created mediaObject handles (e.g. implement Media.list() in Android in addition to Media.get() and implement it in JS API similarily). Then I could loop through all and search for Media with the same src. Or I could stop all playing playing sounds on e.g. leaving the current page.

Contributor guide

Open the contributing guide

Research direction

Start with www/Media.js at the linked lines and inspect how media IDs are generated and retrieved. Compare the Android and iOS handling of existing Media objects. Done means the agreed custom-ID API can reacquire an existing media object after a webview restart and preserves its callbacks; the issue also mentions Media.list() as an alternative to evaluate.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, ios, javascript
Domain
mobile
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.