homerours / cordova-music-controls-plugin Goto Github PK
View Code? Open in Web Editor NEWA Cordova plugin displaying music controls in notifications (cordova-plugin-music-controls)
License: MIT License
A Cordova plugin displaying music controls in notifications (cordova-plugin-music-controls)
License: MIT License
If I skip a song it doesn't update the notification with the correct info, is there an update/modify function available to edit the notification/music player?
I can only get it to work with a web image. Everything I have tried using local has failed.
My local cover in www folder doesnt't show up
every case work find just case 'music-controls-play': it's don't work can you tell me why? this is my function
function events(action) {
switch(action) {
case 'music-controls-next':
$scope.skip();
break;
case 'music-controls-previous':
$scope.back();
break;
case 'music-controls-pause':
$scope.stop();
break;
case 'music-controls-play':
console.log("play click");
$scope.playMedia(playing);
break;
default:
break;
}
}
play click don't show
sorry for my English :"(
Hey everyone,
Hope someone can shed some light on this.
In any iOS build I do the onSuccess callback isn't being called. I've tripled checked the code and it's been implemented as per the documentation. Not sure what is going on here. Please help!
$ionicLoading.show({
template: '<ion-spinner></ion-spinner>',
noBackdrop: true
});
$cordovaMusicControls.create({
track: $rootScope.featuredTrack.name,
artist: $rootScope.featuredTrack.track_narrator.name,
cover: $rootScope.featuredTrack.thumbnail,
duration: $rootScope.featuredTrack.duration,
album: $rootScope.featuredTrack.album_.name, //iOS only
elapsed: getSeconds(trackvm.mediaModel.currentPosition),
ticker: "Now Playing: " + $rootScope.featuredTrack.name, //Android only
isPlaying: false,
dismissable: false,
hasPrev: true, // show previous button
hasNext: true, // show next button
hasClose: false, // show close button
}, onSuccess, onError);
function onSuccess() {
$log.info('BG player activated.');
$ionicLoading.hide();
}
function onError() {
$log.info('BG player failed.');
$ionicLoading.hide();
}
So in the above code the spinner won't go away in iOS and nor does it fire any of the $log comments. Works just fine in Android. It has been wrapped around a $ionicPlatform.ready(function() {} as well.
I'm doing this on AngularJS 1.5 and ionic 1.3.2
Looking forward to some help on this :)
Cheers!
Is better then use 2 plugins...
Please expose this API. The Cordova Media Plugin supports playback rate on iOS. The Music Controls Plugin should have the same support so that the playback timeline can be in sync.
Seeing some issues using local files for covers. If I change to a http:// url to load the image and it works fine and uses the image. If I place a file called absolution.jpg in /albums or even just in the www root and try to load it as per the documentation it is never used and no error is logged to the console.
cover: 'albums/absolution.jpg'
image is not used
cover: 'absolution.jpg'
cover is not used
https://remote.server.com/absolution.jpg
cover IS used.
This is the error reported:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.ComponentName.getPackageName()' on a null object reference at android.media.AudioManager.registerMediaButtonIntent(AudioManager.java:2542) at android.media.AudioManager.registerMediaButtonEventReceiver(AudioManager.java:2534) at com.homerours.musiccontrols.MusicControls.registerMediaButtonEvent(MusicControls.java:49) at com.homerours.musiccontrols.MusicControls.initialize(MusicControls.java:69) at org.apache.cordova.CordovaPlugin.privateInitialize(CordovaPlugin.java:54) at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:169) at org.apache.cordova.PluginManager.exec(PluginManager.java:120) at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59) at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41) at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method) at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:37) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:135) at android.os.HandlerThread.run(HandlerThread.java:61)
I have absolutely no idea what that means...
I noticed that the MusicControls notification keeps getting shown when my app is "killed" by Android after a period of inactivity. If the app is "paused", i.e. put in the background, and I terminate it manually (by swiping it from the recent apps list), the MusicControls notification is closed after a short delay (1-3 sec).
If I keep it in the background, e.g. over night, the app will get killed silently at some time. Apparently, MusicControls does not notice this, and prev/play/next buttons will no longer work. Clicking the track image will restart the app, splash screen and all, though.
Hi guys,
Can we have a method to update the "dismissable" property of the notification without re-creating the whole control? Would like to be able to update this when the media is playing/pausing.
Should be similar to updateIsPlaying(boolean)
Hi,
thanks for this great plugin.
is there any way to make it work with html5 audio tag?
Is it possible to have any control over the visual style of the Android notification control?
I'd prefer it to have a solid black background (not grey) and to use custom icons (I.e. the ones from https://www.google.com/design/icons)
Lockscreen controls and metadata do not appear on an LG V10 running Android 5.1.1. Used the same code successfully on a Nexus 7 also running Android 5.1.1.
Hi,
As it's a best pratice, It'd be nice to have release tags (e.g. v1.3.0) for each new version. This way it's possible to point at that very specific version in automation tools (e.g. npm, bower, jenkins), avoiding breaking anything when there is a new release.
I have a problem the plugin does not work on my android device I did all the steps, I downloaded the git through the console. I added the plugin to config.xml then create a js with the following code
`MusicControls.create({
track : 'Time is Running Out', // optional, default : ''
artist : 'Muse', // optional, default : ''
cover : '', // optional, default : nothing
// cover can be a local path (use fullpath 'file:///storage/emulated/...', or only 'my_image.jpg' if my_image.jpg is in the www folder of your app)
// or a remote url ('http://...', 'https://...', 'ftp://...')
isPlaying : true, // optional, default : true
dismissable : true, // optional, default : false
// hide previous/next/close buttons:
hasPrev : false, // show previous button, optional, default: true
hasNext : false, // show next button, optional, default: true
hasClose : true, // show close button, optional, default: false
// iOS only, optional
album : 'Absolution', // optional, default: ''
duration : 60, // optional, default: 0
elapsed : 10, // optional, default: 0
// Android only, optional
// text displayed in the status bar when the notification (and the ticker) are updated
ticker : 'Now playing "Time is Running Out"'
}, onSuccess, onError);`
And call it in the index.html
<script type="text/javascript" src="js/music-control.js"></script>
But nothing appears on the notification bar
I also use the code on the play buttons but nothing like that does not work
MusicControls.updateIsPlaying(true);
I've tried two ways (on android), i guess im just missing something simple :
`
case 'music-controls-pause':
angular.element(document.getElementById('cont')).scope().playBtn().$apply();
MusicControls.updateIsPlaying(true);
console.log("pause");
break;
case 'music-controls-play':
angular.element(document.getElementById('cont')).scope().playBtn().$apply();
MusicControls.updateIsPlaying(false);///(or this?)//// isPlaying: false,
console.log("pause");
break;
and other way :
` case 'music-controls-media-button-play-pause':
angular.element(document.getElementById('cont')).scope().playBtn().$apply();
if (MusicControls.updateIsPlaying(false)) {
MusicControls.updateIsPlaying(true);///(or this?)//// isPlaying: true,
}
else {
MusicControls.updateIsPlaying(false);
}
break;`
I can set elapsed, but duration doesn't work.
When passing in an image file that exists locally within the app Android is unable to find the file:
window.MusicControls.create({
track: 'Title',
artist: 'Artist',
cover: 'img/logo.jpg',
isPlaying: false,
dismissable: true,
hasPrev: false,
hasNext: false,
hasClose: true
});
03-03 15:40:38.771 31274 31290 W System.err: java.io.FileNotFoundException: img/logo.jpg: open failed: ENOENT (No such file or directory)
On a OnePlus One running Android 6.0.1
Hello guys
is this plugin can play shutcast or icecast ?
As of iOS 11, using init will no longer work to initialize a MPMediaItemArtwork, breaking this plugin on iOS 11. I think the new way of doing it is with a closure (block?): https://developer.apple.com/documentation/mediaplayer/mpmediaitemartwork
Hey everyone,
The elapsed time on the iOS controls keep goes out of sync. Everytime you hit pause it goes back to zero. I've seen other apps using this plugin and they too have simply ignored sending time information to the plugin, which works fine in the notifications area (as iOS hides the time bar) but in the lockscreen it shows an ugly empty time bar.
Is there a way to fix this functionality? If not then is there a way to hide the time bar on the lockscreen?
Your help would be greatly appreciated.
(Angular 1.5, Ionic 1.3.2)
Cheers!
We get reports from our Samsung users that they expect track updates to appear on Samsung's Always-On display, like the way Spotify and others do it (see attached picture). I was expecting this to work out of the box once the track information is pushed to the OS via this plugin, but apparently it doesn't?
Can this be implemented in cordova-music-controls-plugin
?
What do you think about caching the cover image?
I'm loading images from other server and it takes too much time to Create() terminate. When changing the music it's ok, since there is new data, but it's pretty dumb to re-download the image everytime user play/pause music.
Maybe creating a method 'tooglePlay()', which would recreate the notification using the same info just toggling the isPlaying would be a better approach.
I want to create a pull request for data, but I don't know when I'll have available time. Maybe this Sunday I'll do that.
Let me know what you think about so we can work on it.
MusicControls is called in a function
function playmusic(){
try {
MusicControls.create({
track : 'My track',
artist : 'my subttile',
cover : 'img/Musical Notes-100.png',
isPlaying : true,
ticker : 'Now playing ......'
}, onSuccess, onError);
}catch(e){
console(e.message);
}
}
console(e.message); Returns MusicControls.create is undefined please how do I solve this?
Missing a comma after: album : 'Absolution'
in the docs
heloo, i have question.
i use this plugin and there's an error "Uncaught ReferenceError: MusicControls is not defined"
can someone told me why ?
Hi,
First thanks to this great plugin. I have integrated this into my app successfully and works great. I want to prevent my app opens. I am not mean the icon buttons.
Hi!
Thanks for this plug-in (I think)
I can't get it to work in my Ionic 2 project. It has probably nothing to do with the plugin it self.
In my ts I have:
import {MusicControls} from 'ionic-native';
//--
showMusicControls = function(){
MusicControls.create({
track : 'Time is Running Out', // optional, default : ''
artist : 'Muse', // optional, default : ''
cover : 'albums/absolution.jpg', // optional, default : nothing
}, onSuccess, onError);
};
But I get three errors:
Cannot find name 'onSuccess'.at line
Cannot find name 'onError'.at line
Supplied parameters do not match any signature of call target.at line
Can you please show how to create Musiccontrols in Ionic 2?
I must custom notification icon when i play music.
from play and pause icon.
I set these properties to false, but the music controls on iOS still show the prev/next buttons.
There is a method to update the status of playing/paused, but what is the correct way to update the elapsed time?
Should I create a new control?
Hi,
music-controls-media-button works great but wouldn't it be better to send the keyCode, for example, as a second parameter to the "MusicControls.subscribe(events)" function since the variable "KeyEvent event" in MusicControlsBroadcastReceiver.java already has that value?
Then one could have different actions for example:
KEYCODE_MEDIA_PREVIOUS
KEYCODE_MEDIA_NEXT
My car acts as a bluetooth headset for my phone and all media control keys just fire the music-controls-media-button event and I can't differentiate the prev/next event from play/pause event.
Hi,
I'm developing a music app with cordova.
The question may seem stupid but I can't figure out how to make it work.
I've tried this:
ionic start myapp
cd myapp
cordova plugin add https://github.com/homerours/cordova-music-controls-plugin
Then I created a button and linked it to a function which does .create()
.subscribe()
and listen()
at the MusicControls
variable. I've inspected it using chrome and MusicControls
is correctly populated. The button click function is being called as well.
When the button is clicked it shows nothing.
I've tried searching for bugs at the plugin source code, both the JS interface and the Java code seem ok to me.
Can you help me?
Thanks in advance
Is it possible to somehow create the controls and indicate the duration of a medium, without specifying a media file?
This would be useful for applications that stream media on demand. It would allow the user to seek to an arbitrary position and a callback would send the requested position to the server, which would in turn seek to that position in the local media file and stream from there on.
i tested in android only yet,
In MusicControls updateIsPlaying( panel only pause is showing as icon ) , is it possible to do like normal player pause and play toggle icon as well as event.?
right now i can see only pause icon and even if i clicked many time it's calling pause audio event only,
even if i tried MusicControls.updateIsPlaying(true);
still only pause audio not playing again and not even update icon for play/pause toggle.
I am using android 6.0.1
Please help
I check this plugin android 4.1.2 and 4.2.2 but it does not work,
it only work android 5.
I see this error on logcat.
Do you have a solution ?
01-27 23:21:56.568 26101-26101/com.ionicframework.example403106 W/dalvikvm: VFY: unable to resolve virtual method 137: Landroid/media/AudioManager;.registerMediaButtonEventReceiver (Landroid/app/PendingIntent;)V 01-27 23:21:56.568 26101-26101/com.ionicframework.example403106 W/dalvikvm: VFY: unable to resolve virtual method 139: Landroid/media/AudioManager;.unregisterMediaButtonEventReceiver (Landroid/app/PendingIntent;)V 01-27 23:21:56.578 26101-26101/com.ionicframework.example403106 W/System.err: java.lang.NoSuchMethodError: android.media.AudioManager.registerMediaButtonEventReceiver 01-27 23:21:56.578 26101-26101/com.ionicframework.example403106 W/System.err: at com.homerours.musiccontrols.MusicControls.registerMediaButtonEvent(MusicControls.java:50) 01-27 23:21:56.578 26101-26101/com.ionicframework.example403106 W/System.err: at com.homerours.musiccontrols.MusicControls.initialize(MusicControls.java:75) 01-27 23:21:56.578 26101-26101/com.ionicframework.example403106 W/System.err: at org.apache.cordova.CordovaPlugin.privateInitialize(CordovaPlugin.java:56) 01-27 23:21:56.583 26101-26101/com.ionicframework.example403106 W/System.err: at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:171) 01-27 23:21:56.583 26101-26101/com.ionicframework.example403106 W/System.err: at org.apache.cordova.PluginManager.exec(PluginManager.java:122) 01-27 23:21:56.583 26101-26101/com.ionicframework.example403106 W/System.err: at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59) 01-27 23:21:56.583 26101-26101/com.ionicframework.example403106 W/System.err: at org.apache.cordova.CordovaBridge.promptOnJsPrompt(CordovaBridge.java:135) 01-27 23:21:56.583 26101-26101/com.ionicframework.example403106 W/System.err: at org.apache.cordova.engine.SystemWebChromeClient.onJsPrompt(SystemWebChromeClient.java:124) 01-27 23:21:56.583 26101-26101/com.ionicframework.example403106 W/System.err: at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java) 01-27 23:21:56.583 26101-26101/com.ionicframework.example403106 W/System.err: at android.os.Handler.dispatchMessage(Handler.java) 01-27 23:21:56.583 26101-26101/com.ionicframework.example403106 W/System.err: at android.os.Looper.loop(Looper.java) 01-27 23:21:56.588 26101-26101/com.ionicframework.example403106 W/System.err: at android.app.ActivityThread.main(ActivityThread.java) 01-27 23:21:56.588 26101-26101/com.ionicframework.example403106 W/System.err: at java.lang.reflect.Method.invokeNative(Native Method) 01-27 23:21:56.588 26101-26101/com.ionicframework.example403106 W/System.err: at java.lang.reflect.Method.invoke(Method.java:511) 01-27 23:21:56.588 26101-26101/com.ionicframework.example403106 W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java) 01-27 23:21:56.588 26101-26101/com.ionicframework.example403106 W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java) 01-27 23:21:56.588 26101-26101/com.ionicframework.example403106 W/System.err: at dalvik.system.NativeStart.main(Native Method) 01-27 23:21:56.598 26101-26101/com.ionicframework.example403106 W/System.err: java.lang.NoSuchMethodError: android.media.AudioManager.registerMediaButtonEventReceiver 01-27 23:21:56.598 26101-26101/com.ionicframework.example403106 W/System.err: at com.homerours.musiccontrols.MusicControls.registerMediaButtonEvent(MusicControls.java:50) 01-27 23:21:56.598 26101-26101/com.ionicframework.example403106 W/System.err: at com.homerours.musiccontrols.MusicControls.initialize(MusicControls.java:75) 01-27 23:21:56.598 26101-26101/com.ionicframework.example403106 W/System.err: at org.apache.cordova.CordovaPlugin.privateInitialize(CordovaPlugin.java:56) 01-27 23:21:56.598 26101-26101/com.ionicframework.example403106 W/System.err: at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:171) 01-27 23:21:56.603 26101-26101/com.ionicframework.example403106 W/System.err: at org.apache.cordova.PluginManager.exec(PluginManager.java:122) 01-27 23:21:56.603 26101-26101/com.ionicframework.example403106 W/System.err: at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59) 01-27 23:21:56.603 26101-26101/com.ionicframework.example403106 W/System.err: at org.apache.cordova.CordovaBridge.promptOnJsPrompt(CordovaBridge.java:135) 01-27 23:21:56.603 26101-26101/com.ionicframework.example403106 W/System.err: at org.apache.cordova.engine.SystemWebChromeClient.onJsPrompt(SystemWebChromeClient.java:124) 01-27 23:21:56.603 26101-26101/com.ionicframework.example403106 W/System.err: at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java) 01-27 23:21:56.603 26101-26101/com.ionicframework.example403106 W/System.err: at android.os.Handler.dispatchMessage(Handler.java) 01-27 23:21:56.603 26101-26101/com.ionicframework.example403106 W/System.err: at android.os.Looper.loop(Looper.java) 01-27 23:21:56.603 26101-26101/com.ionicframework.example403106 W/System.err: at android.app.ActivityThread.main(ActivityThread.java) 01-27 23:21:56.603 26101-26101/com.ionicframework.example403106 W/System.err: at java.lang.reflect.Method.invokeNative(Native Method) 01-27 23:21:56.608 26101-26101/com.ionicframework.example403106 W/System.err: at java.lang.reflect.Method.invoke(Method.java:511) 01-27 23:21:56.608 26101-26101/com.ionicframework.example403106 W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java) 01-27 23:21:56.608 26101-26101/com.ionicframework.example403106 W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java) 01-27 23:21:56.608 26101-26101/com.ionicframework.example403106 W/System.err: at dalvik.system.NativeStart.main(Native Method)
Trying the following code (and everything ... after the device is ready obviously) in android 5.1 doesn't work :( the app just crashes
MusicControls.create({
track : 'Time is Running Out', // optional, default : ''
artist : 'Muse', // optional, default : ''
//cover : 'albums/absolution.jpg', // optional, default : nothing
isPlaying : true, // optional, default : true
dismissable : true, // optional, default : false
// hide previous/next/close buttons:
hasPrev : false, // show previous button, optional, default: true
hasNext : false, // show next button, optional, default: true
hasClose : true, // show close button, optional, default: false
// Android only, optional
// text displayed in the status bar when the notification (and the ticker) are updated
//ticker : 'Now playing "Time is Running Out"'
});
Is this version of android unsupported ?
Hi! is there any way to put an image of current song in lock screen? like spotify does? it will be great!
Hello! do you have any plans to migrate to RN?
Hello,
I am not able to see play,next and previous buttons on xiomi redmi prime 2 phone which has android kitkat 4.4.4 and MIUI7. It is working on Sony xperia and other android phones but not on MIUI. Please check the issue. Thanks.
I have this small template: https://github.com/GerardoLSJ/cordova-download-template-to-private-directory
On Android >= 4.1.2 works fine (after the alert when you push "play")
On iOS simulator too but in an actual device nothing is displayed :/
Any ideas?
Found this in the code when I was trying to figure out how I can add prev/next buttons
NSNumber * duration = [NSNumber numberWithInt:[musicControlsInfo elapsed]];
NSNumber * elapsed = [NSNumber numberWithInt:[musicControlsInfo elapsed]];
Guess I should tag @0505gonzalez on this?
Hi
i am using shoutcast mp3 url as media and its playing fine in app but when app in background and controls showing in toolbar after certain seconds player get stopped
I can't install version 1.4.0 because of a wrong version in package.json
Whenever the app is minimized, the notification controls are discarded. This happens regardless of dismissbale
. Is this by design?
Could it be possible to add the ability to hide the next/previous buttons when creating/updating the notification? People tell me its confusing when they're at the end of a playlist but the "next" button is still there.
I have cover set to this path: assets/img/music-placeholder.png
, which is under /www
folder. However on iOS this doesn't set the cover image. Any idea?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.