Open ds8k opened 9 years ago
It looks dead simple with the new MediaSession class, which is designed to allow you to report media playback to the rest of the system.
https://developer.android.com/reference/android/media/session/MediaSession.html
Although unfortunately that requires api 21.
I could use android support as well. Is there any plans to support Android? @ds8k did you end up finding a solution?
For Android support, you can have a look at cordova-plugin-music-controller. It might however not be perfect...
Nice @homerours. I haven't tested your code but the api seems similar. Want to merge your project into this one to provide folks with a more complete remote controls plugin?
Yes, that would be a good solution. But maybe it would be better that you update your JS API to make it easier to understand: use object (instead of arrays) for notifications infoos. Also, why do you fire a DOM event instead of running aa user callback? You can have a look at MusicController.js to see what I mean.
Cool. When you say notification infos, do you mean passing data from js to ios? From examples I've seen, using a array is pretty common. But happy to explore using JSON. I'm down to refactor out the dom event in place of a callback - makes sense.
I'll create a branch and add you as a contributor to the project. We'll work off the branch and go from there. Sound good?
Sounds good. About notifications info, I mean that it would be easier for the end-user to pass an object as argument rather than an array (and have to remember "1=song, 2=artist ..."). It would also make the code easier to understand.
Cool I agree.
created this branch https://github.com/shi11/RemoteControls/tree/androidWindows
@shi11 @homerours This is fantastic! I've installed this branch on my project and it was easy to integrate into my html5 audio player code. I had been using this for iOS and was excited to see the addition for Android and Windows.
I may not be able to help with code commits, but I would love to participate by providing feedback while testing. Is this the best place to provide feedback or should I open new tickets? I'll be testing iOS and Android on a multitude of devices.
On android I notice that there is no event called for when a phone call is coming in or some other app plays audio or should interrupt, such as google earth. Is this even possible?
Thanks for this!
@homerours I'm running this branch on android. I found that there is a bug, but I don't know how to fix. I am able to get the code running on android devices that I have for testing which are 4.1.2 and 5.0.2 by commenting out the following starting at line 43 on MusicControls.java:
// Register pendingIntent for broacast
public void registerMediaButtonEvent(){
//this.mAudioManager.registerMediaButtonEventReceiver(this.mediaButtonPendingIntent);
}
public void unregisterMediaButtonEvent(){
//this.mAudioManager.unregisterMediaButtonEventReceiver(this.mediaButtonPendingIntent);
}
@pvandrunen Thank you very much for this feedback! This fonctions are used to listen to the headset button. It should intercept the click event (that is usually linked to default android music player). What kind of bug did you experienced when uncommenting those lines? (I'm running the plugin on android 4.4 device and android 5.1 emulator without bugs) (Sorry for the delay) for your previous message, when a phone call is coming, I notices that android pause all audio listening. When the call is over, everything is running as before. So I think that this behaviour is "acceptable". I don't know if it's possible to detect when other apps starts playing audio, I will investigate it ! Sorry again for the delay
Thanks for the response. Before uncommenting those lines there was an error message, which I found in the logs about a class being undefined (I think) so the API had no effect - the controls would not appear in the notification area on the decides in had listed. Interestingly the Controls DID work on android 4.4 but I upgraded that device to 5.0 and the controls no longer appear.
When I am back at my desk I will send more details.
Phil
On Friday, October 23, 2015, homerours notifications@github.com wrote:
@pvandrunen https://github.com/pvandrunen Thank you very much for this feedback! This fonctions are used to listen to the headset button. It should intercept the click event (that is usually linked to default android music player). What kind of bug did you experienced when uncommenting those lines? (I'm running the plugin on android 4.4 device and android 5.1 emulator without bugs) (Sorry for the delay) for your previous message, when a phone call is coming, I notices that android pause all audio listening. When the call is over, everything is running as before. So I think that this behaviour is "acceptable". I don't know if it's possible to detect when other apps starts playing audio, I will investigate it ! Sorry again for the delay
— Reply to this email directly or view it on GitHub https://github.com/shi11/RemoteControls/issues/10#issuecomment-150542605 .
Philip Van Drunen Journey Multimedia, Inc. ☎ 970-673-7872
Please try the code at the original repo. The code I pushed on the android branch is a little bit outdated and may cause bugs.
any news? is the branch ready to use it or still in development state?
It sounds good to see two developers unite their efforts towards community
Any plans on the Android support? If you still want it, I might open a PR with the code to make it work.
Oh cool @Guichaguri yeah that'd be great. I definitely dropped the ball on this but if you wanted to run with it and create a PR that'd be great.
It's really easy to get it working on Android, but it will need some API changes. Currently, the API only supports artist, title, album, image, duration and elapsed time. There are a lot of other properties that can be implemented. I was thinking about optional properties, and other ones that are only used on Android or iOS.
Android currently supports: artist, title, album, image, duration, elapsed time, state, volume, speed, buffered position, rating, description, release date, genre, and many other properties
Here is what I was thinking:
window.remoteControls.updateMetadata({
title: '',
artist: '',
album: '',
cover: '',
duration: 0,
rating: 75,
description: '',
date: '',
genre: ''
});
window.remoteControls.updatePlayback({
elapsedTime: 0,
bufferedTime: 0,
volume: 100,
state: 1, // -1: Error, 0: Stopped, 1: Playing, 2: Paused, 3: Buffering
speed: 1
});
window.remoteControls.updateActions({
play: true,
pause: true,
stop: false,
seekTo: false,
skipToNext: true,
skipToPrevious: true,
rate: true,
volume: true
});
document.addEventListener("remotecontrols", function(event) {
switch(event.action) {
case 'play':
case 'pause':
case 'stop':
// Handle basic controls
break;
case 'volume':
// Handle new volume
//event.volume
break;
case 'seek':
// Handle new playback position
//event.position
break;
case 'next':
case 'previous':
// Handle skipping
break;
case 'rate':
// Handle rating
//event.rating
break;
}
});
I don't know which of them are supported by iOS, I only added the most important properties from Android, and also, most of them are optional. We should still support the old function and event for compatibility purposes.
@shi11 What do you think?
Nice @Guichaguri. I think it looks good. We should research what is supported in iOS. What do other folks think?
I got it working on Android with the new API. I'll open a PR when I fix and test everything
It should work with API 14+ (98.2% of the Android users)
Done! #32
What's happened? Can we get that merged? Be keen to use this for Speaking Email
Is this just too hard to accomplish on Android? I've been looking all over for an Android version of this plugin and it simply doesn't exist. What's the deal?