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

No way to change meta info and Destroy needs to be invoked twice #90

Open
SimoneVB opened this issue Dec 8, 2022 · 15 comments
Open

No way to change meta info and Destroy needs to be invoked twice #90

SimoneVB opened this issue Dec 8, 2022 · 15 comments

Comments

@SimoneVB
Copy link

SimoneVB commented Dec 8, 2022

I'm using this plugin on Android 12, on my Xiaomi 11 lite.

The 1st thing:
I was trying to change the meta info when the MediaControls is already created,
when my app goes from one song to the next one.

It seems like there's no way to update those data: no "updateData" method.
So, I've invoked a 2nd "create" but it doen't seems to be the right approach: both track and artist name change,
but the cover doesn't. The cover stays the same given with the previous "create" calling.

So I've decided to destroy and re-create the MediaControl each time my app changes song;
but I've found that just one destroy calling isn't enough! I actually need to invoke the destroy twice,
to be able to really remove the MediaControl

this.musicControls.destroy().then((result) => { this.musicControls.destroy().then((result) => { console.log('destroy', result) }) })

@ghenry22
Copy link
Owner

ghenry22 commented Dec 9, 2022

My primary use is also for a music player app so I just had a look at my own code. I don't call destroy at all, just call create with new details each time the track changes, it will replace the existing instance by default.

So for example when I catch the playback complete event, I start playback of the next track and call updateRemoteControls() which does a create() with new details, subscribe() and listen() for events. Once catch to look out for is to start the media playing first so that there is an active audiosession.

@bikubi
Copy link

bikubi commented Dec 10, 2022

I've ran into the "destroy twice" problem, too, but even then it was unreliable, even (maybe) leading to app crashes. My solution/workaround was to not use destroy, and instead keep the notification dismissable. (And, of course, not destroy before each update.)

@ghenry22
Copy link
Owner

I’ll have a look at the destroy handling and see if I can reproduce this behaviour.

@bikubi
Copy link

bikubi commented Dec 10, 2022

@ghenry22 IIRC it wasn't consistent wrt android/ios and their versions. Wish I had taken better notes, sorry!

@bikubi
Copy link

bikubi commented Dec 10, 2022

@ghenry22 I went through my code and I had figured this out:

  • on Android, destroy twice (second one with setTimeout 1000ms)
  • on iOS, never destroy (IIRC because of crashes)

but this is in dead code now effectively since I don't show the close button any more (it was too tough to figure out consistently with dismissable and the new Android 13 carousel)...

Sorry for the info trickle, I hope it's not causing more confusion.

@SimoneVB
Copy link
Author

I've read all your answers, but I didn't find out a way to make this component work properly. Followings are the problems I'm facing to, while I'm debugging my app:

  1. a new create doesn't update the cover: the cover remain the same as the previous track. So, it seems I need to destroy the component before, to be able to update all the infos

  2. the method updateRemoteControls you suggested, doesn't really exists (https://github.com/ghenry22/cordova-plugin-music-controls2/blob/master/www/MusicControls.js)

  3. Providing the duration and the elapsed time during the create is totally superfluous, since the Android component does not support these two pieces of informations (https://github.com/ghenry22/cordova-plugin-music-controls2/blob/master/src/android/MusicControls.java and https://github.com/ghenry22/cordova-plugin-music-controls2/blob/master/src/android/MusicControlsInfos.java)

  4. For the same reason, the updateElapsed method doen't take any effect. Obivioysly, since the component doesn't know the real track duration.

If you all have any suggestions to solve these problems on Android, please let me know them. What I'm trying to do is to implement e Media Notification as Spotify do. Unfortunately, this component seems to be unable to give me that.

@bikubi
Copy link

bikubi commented Dec 13, 2022

@SimoneVB

  1. can't confirm. Are the other (textual) infos updating & only the cover image is stuck?
  2. updateRemoteControls is an example for ghenry's/my/your implementation of an update function, which calls create and does your specific updates
  3. progress/scrubbing AFAIK not implemented on Android yet. See this comment on Progress bar not showing in android #54 and the README:
    // iOS only, optional
    //...
    duration : 60, // optional, default: 0
    elapsed : 10, // optional, default: 0
    //...
    hasScrubbing : false, //optional. default to false. Enable scrubbing from control center progress bar 
  4. same reason as 3

So, yes, at this moment, this plugin (not a component, sorry to nitpick) is not able to give you that, from my understanding.

@brunolau
Copy link

What helped me in updating the cover picture is calling the create method multiple times. My scenario is I have wrapped the media controls functions into Promise, I'm attaching a snippet from my code that works for me

await AudioPlayerProvider.initMediaControls(position, false); //call to "create" method
await AudioPlayerProvider.updatePosition(position, false); //call to "updateElapsed" method
await AudioPlayerProvider.initMediaControls(position, false); //call to "create" method again

setTimeout(() => {
    AudioPlayerProvider._track.getCurrentPosition(async (position) => { //this obtains current position from cordova Media object
        if (position > -1 && AudioPlayerProvider._isPlaying) {
            await AudioPlayerProvider.initMediaControls(position, false);  //call to "create" method once again
        }
    });
}, 2000); 

I'm not sure if all this blabber is needed (almost certainly sure that not), however it did solve the issue with cover picture not refreshing for me

@SimoneVB
Copy link
Author

SimoneVB commented Dec 16, 2022

@brunolau
That are a lot of things not working with this plugin, at least on Android (I didn't test it on iOS): headset events actually they don't seem to work; the same for the volume buttons, I cannot really listen for their events on my Android 12; the destroy method actually destroys only when invoked twice; the create method doesn't update the cover when a notification is already created. Last but not least, that progress bar - with its song duration and elapsed time.

I can see there are many commits here, from many contributors, since the 2017... but still missing features. I know this isn't a job for no one. But, in my opinion, since a plugin is sponsored by Ionic as the "official" plugin to do some things (https://ionicframework.com/docs/native/music-controls), that plugin should be developed and maintained as better as its owner can do it.

The progress bar feature on Android is requested since almost 2 years by the users here. Today is still not supported. It actually took me 10 minutes to implement it on Android (and I'm not a Java developer). Now I'm working to fix both the destroy, the cover updating, and the headset and volume-buttons event.

screen

@bikubi
Copy link

bikubi commented Dec 16, 2022

@SimoneVB

But, in my opinion, since a plugin is sponsored by Ionic as the "official" plugin to do some things

I think you're off here. I do not get "sponsored" in any sense, maybe "endorsed"? Or did you mean Capacitor? This is not a Capacitor plugin, it's a Cordova Community Plugin:

These plugins are submitted and maintained by the Ionic community. While community members are generally quick to find and fix issues, certain plugins may not function properly.

I hope you will fashion a PR from your welcome updates, I will gladly help to test.

@SimoneVB
Copy link
Author

I think you're off here. I do not get "sponsored" in any sense, maybe "endorsed"?

Yes, I meant "endorsed" or something like that. Sorry for my bad english: I'm not a native. I meant to tell this plugin is mentioned over the Ionic page I've linked above.

@bikubi
Copy link

bikubi commented Dec 16, 2022

Alright, language issue, no worries & sorry!

But, I think it's important to acknowledge that the Ionic endorsement is -- and I'm guessing here -- rather unilateral, and maybe even something of a burden?

that plugin should be developed and maintained as better as its owner can do it.

I feel like Ionic is happy to have something to point to, but I think their page could be worded better. It seems to bring in a sense of entitlement, from what I've seen in other plugins in the cordova ecosystem (and other places where certain commercial dev clashes with FOSS ideas). And while the owner theoretically profits from more attention -- in that there are more potential contributors for their own use of the plugin they "own" -- I don't think that the owner owes anybody anything. I'm happy this fork even exists!

A different read: this plugin is "developed and maintained as best as its owner can do it". If their best is not good enough for you, contribute (as you've already started to), or fork, or complain at Ionic.

On a personal note, as somebody who fell into the Cordova ecosystem and is struggling with sunk cost dread, I feel your frustration, but the (remaining) plugin maintainers are not the ones to blame.

And to re-state & bring this back on topic, I will be happy to contribute to your efforts.

@ghenry22
Copy link
Owner

@brunolau That are a lot of things not working with this plugin, at least on Android (I didn't test it on iOS): headset events actually they don't seem to work; the same for the volume buttons, I cannot really listen for their events on my Android 12; the destroy method actually destroys only when invoked twice; the create method doesn't update the cover when a notification is already created. Last but not least, that progress bar - with its song duration and elapsed time.

I can see there are many commits here, from many contributors, since the 2017... but still missing features. I know this isn't a job for no one. But, in my opinion, since a plugin is sponsored by Ionic as the "official" plugin to do some things (https://ionicframework.com/docs/native/music-controls), that plugin should be developed and maintained as better as its owner can do it.

The progress bar feature on Android is requested since almost 2 years by the users here. Today is still not supported. It actually took me 10 minutes to implement it on Android (and I'm not a Java developer). Now I'm working to fix both the destroy, the cover updating, and the headset and volume-buttons event.

screen

That's cool that you managed to implement some new functionality! Please do submit a pull request with your changes to enable the new functionality and I am very happy to test and merge it.

I maintain this entirely in my spare time for free, I have no involvement or endorsement from Ionic or anyone else. It's just me working for free. If you would also like to contribute some of your time for free that would be awesome and help to keep the plugin up to date :)

The Ionic docs simply provide basic instructions on how to use their ionic-native wrapper with various plugins to make development easier and more approachable, even these docs and wrapper are maintained by the community these days under the awesome-cordova-plugins project.

@LuisUcla
Copy link

@brunolau That are a lot of things not working with this plugin, at least on Android (I didn't test it on iOS): headset events actually they don't seem to work; the same for the volume buttons, I cannot really listen for their events on my Android 12; the destroy method actually destroys only when invoked twice; the create method doesn't update the cover when a notification is already created. Last but not least, that progress bar - with its song duration and elapsed time.
I can see there are many commits here, from many contributors, since the 2017... but still missing features. I know this isn't a job for no one. But, in my opinion, since a plugin is sponsored by Ionic as the "official" plugin to do some things (https://ionicframework.com/docs/native/music-controls), that plugin should be developed and maintained as better as its owner can do it.
The progress bar feature on Android is requested since almost 2 years by the users here. Today is still not supported. It actually took me 10 minutes to implement it on Android (and I'm not a Java developer). Now I'm working to fix both the destroy, the cover updating, and the headset and volume-buttons event.
screen

That's cool that you managed to implement some new functionality! Please do submit a pull request with your changes to enable the new functionality and I am very happy to test and merge it.

I maintain this entirely in my spare time for free, I have no involvement or endorsement from Ionic or anyone else. It's just me working for free. If you would also like to contribute some of your time for free that would be awesome and help to keep the plugin up to date :)

The Ionic docs simply provide basic instructions on how to use their ionic-native wrapper with various plugins to make development easier and more approachable, even these docs and wrapper are maintained by the community these days under the awesome-cordova-plugins project.

How will we know if these improvements have already been implemented? When can we download the plugin again?

@rideo-eduardmorales
Copy link

rideo-eduardmorales commented Aug 30, 2024

@SimoneVB It's been a while, but could you please share your improvements regards the progress bar? It doesn't matter if the work is not finished, we can continue it :)

@ghenry22 by the way, I'm not a java developer, but SimoneVB said it was not hard to implement. Are you planning to have a look at this? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants