apache / apache/cordova-plugin-media
How to release() properly
- Dominant language
- JavaScript
- Stars
- 391
- Forks
- 762
- PR merge metrics
- No merged PRs in 30d
Description
Many thanks for the wonderful plugin. I am using it in many ionic 3 projects and it works great! However, I am facing some resource release issue and I don't know how to address.
I have a list of song
song1
song2
song3
…
When user tap song1, I play song1.mp3. If user tap song2 before song1 finishes, I’d like to stop song 1 and start playing song2. My question is how to do it without memory leaking.
I tried:
```
play(song) {
const file: MediaObject = this.media.create('song');
// to listen to plugin events:
file.onStatusUpdate.subscribe(status => console.log(status)); // fires when file status changes
file.onSuccess.subscribe(() => console.log('Action is successful'));
file.onError.subscribe(error => console.log('Error!', error));
// play the file
file.play();
}
```
I don’t know how to stop and release the previous song. Can anyone help?
Contributor guide
Research direction
Start with the play(song) example and the MediaObject returned by media.create('song'). Trace the plugin's existing lifecycle behavior for switching from one song to another, including the subscribed events. Done means the previous song can be stopped and released when a new song starts without the reported resource leak.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100