cordova-music-controls-plugin icon indicating copy to clipboard operation
cordova-music-controls-plugin copied to clipboard

[ios] Works in the simulator but not in actual device

Open GerardoLSJ opened this issue 8 years ago • 50 comments

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?

GerardoLSJ avatar Jan 03 '17 19:01 GerardoLSJ

Tried to deploy music controls in ionic 1 using the side menu starter template.installed the plugin and added this code the controller, works on android devices and ios simulator, but nothing is happening on IOS device. I also included the controller.js file here

controllers.js.txt

` $cordovaMusicControls.create({ track : 'My Music', // optional, default : '' artist : 'Live Stream', cover : "", isPlaying : false, // 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 }, onSuccess, onFailure);

function events(action) {
  console.log(action);
  switch(action) {
    case 'music-controls-pause':
    $cordovaMusicControls.updateIsPlaying(false);
      console.log("pausing it");
    break;
    case 'music-controls-play':
      console.log("playing it");
      $cordovaMusicControls.updateIsPlaying(true);
    break;
    case 'music-controls-destroy':
      break;
    // Headset events (Android only)
    // Do something
      break;
    case 'music-controls-headset-plugged':
    // Do something
      break;
    default:
      break;
  }
}


// Register callback
$cordovaMusicControls.subscribe().subscribe(events);

// Start listening for events
// The plugin will run the events function each time an event is fired
$cordovaMusicControls.listen();
$cordovaMusicControls.updateIsPlaying(false);`

kailashanath avatar Jan 03 '17 20:01 kailashanath

Hey guys, seems like the npm repository (which cordova and ionic cli tools use to install plugins) is not yet updated. I've asked @homerours to release the latest.

0505gonzalez avatar Jan 03 '17 22:01 0505gonzalez

@GerardoLSJ Seems you got it working on emulator, make sure you start playing audio, this will switch music controls context over to your app. Let me know iOS version on your device and I will take a look as well.

0505gonzalez avatar Jan 03 '17 22:01 0505gonzalez

@0505gonzalez Thanks for the fast response, I have checked it on the devices running IOS 9.3.2 and 10.2 and both of them are not showing any music controls

kailashanath avatar Jan 03 '17 22:01 kailashanath

               my_media.play();

		MusicControls.create(notificationData, function(success){
			console.log('SUCCESS SHOW: '+success);
		},function(error){
			console.log('ERROR SHOW: '+error);
		});

}`

I know there is sound before the MusicControl.Create(), but I'm not sure if this is the best aproximation, the emulator is running 10.1, my device is running 10.0.2

I try using a setTimeout() in case there was a delay of the "media.play()" but nothing happen

GerardoLSJ avatar Jan 03 '17 23:01 GerardoLSJ

I update my template: https://github.com/GerardoLSJ/cordova-download-template-to-private-directory

I was getting the audio from an interal location with the plugin Media.

I change to an html5 audio tag

var audio = document.getElementById("myAudio"); audio.play();

And It seems to work img_0140

GerardoLSJ avatar Jan 04 '17 17:01 GerardoLSJ

@GerardoLSJ are you able to change the title in the music control? As far as i know, this music control is automatically generated from the html 5 audio element, that is why there is no title and the url is showing. It is not created by the music control plugin.

kailashanath avatar Jan 04 '17 18:01 kailashanath

On the init it appears the title and album that I give it, after I push pause appears the URL, I'm going to try to modify this. I have to give it a little "SetTimeout" (800ms) I think it override the information from the HTML5 tag or something, once I click something it returns to the normal "url"

img_0141 img_0143

GerardoLSJ avatar Jan 04 '17 18:01 GerardoLSJ

@GerardoLSJ thanks for the plugin.

I'm experiencing the same issue you have described above.

And it works on iOS simulator but unfortunately not on my device.

I've tried add to the config.xml some parameters but still didn't work

<feature name="BackgroundAudio"> <param name="ios-package" value="BackgroundAudio" /> <param name="onload" value="true" /> </feature>

Cheers

re2005 avatar Jan 06 '17 19:01 re2005

I'm using https://ionicframework.com/docs/v2/native/mediaplugin/ to play the audio, in my case a timeout is not required. This plugin does not override the data displayed in controls

0505gonzalez avatar Jan 06 '17 22:01 0505gonzalez

https://github.com/shi11/RemoteControls

this plugin still works well for music controls on iOS. It might serve as a good reference.

ghenry22 avatar Jan 18 '17 04:01 ghenry22

Any update on this issue?

soramister avatar Jan 18 '17 22:01 soramister

@soramister @GerardoLSJ Do you guys have sample code I can try out? I'm not able to reproduce

0505gonzalez avatar Jan 23 '17 10:01 0505gonzalez

I'd be glad to help if I can repro the problem

0505gonzalez avatar Jan 23 '17 10:01 0505gonzalez

I created a repository with a blank application here: https://github.com/soramister/TestMusicControls

It contains just a play/pause button. If you play the music on the simulator, the plugin works, but not in a real iOS device.

soramister avatar Jan 24 '17 15:01 soramister

https://github.com/GerardoLSJ/cordova-download-template-to-private-directory

This one is in Phonegap/Cordova plain, I download a song from the internet show up an "alert" and then once I push "Play" button in the simulator appears but in device dont'

GerardoLSJ avatar Jan 24 '17 20:01 GerardoLSJ

Any updates?

soramister avatar Feb 03 '17 20:02 soramister

Thanks for the plugin! I am using it on ionic2 application but I have the same problem! In the simulator works well but not in device :(

brainrepo avatar Feb 05 '17 09:02 brainrepo

Yes, same problem here. Using ionic2 too.

ramoncarreras avatar Feb 06 '17 09:02 ramoncarreras

Hi I am using Phonegap, this plugin works in Android but not working on iPhone or iPad. Is there anything additional plugin I have to install to make works in iOS and iPad. Please help me.

Mushaqdeen-J avatar Feb 09 '17 08:02 Mushaqdeen-J

@0505gonzalez Have you been able to reproduce the problem with the code I posted?

soramister avatar Feb 14 '17 08:02 soramister

+1 help please

gbelmm avatar Feb 14 '17 21:02 gbelmm

+1 Works in simulator but not on device.

Device ios 10.2.1
Cordova CLI: 6.5.0 Ionic Framework Version: 2.0.1 Ionic CLI Version: 2.2.1 Ionic App Lib Version: 2.2.0 Ionic App Scripts Version: 1.1.0 ios-deploy version: 1.9.1 ios-sim version: Not installed OS: macOS Sierra Node Version: v6.9.5 Xcode version: Xcode 8.2.1 Build version 8C1002

Any further settings then Inter-App Audio and Background Modes required in Xcode that we are missing maybe?

erikpolder avatar Feb 19 '17 12:02 erikpolder

Sorry guys been pretty busy, I'll give this a try soon.

0505gonzalez avatar Feb 20 '17 07:02 0505gonzalez

@soramister do you have the background audio capability enabled on your project?

0505gonzalez avatar Feb 20 '17 22:02 0505gonzalez

@soramister I tried your example and was able to reproduce. However, I haven't gotten to the bottom of the issue in your repo. I rebuilt the example from scratch and was able to get it working on a physical device properly. Here's an example. https://github.com/0505gonzalez/music-controls-example

Can someone try and let me know if it works for you? And @soramister let me know if you find out why your example does not work properly, I did not have much time to inspect carefully.

0505gonzalez avatar Feb 21 '17 07:02 0505gonzalez

Suddenly it start working for me as well. I did platform rm ios. Removed all plugins. Installed all plugins. Added the ios platform. Reinstalled my certificates from Apple. Updated the xcode project with the suggested settings as Xcode suggested. Enabled the Capabilities. After that running the app on device everything worked as it should. Before all this I tried the steps one by one without luck. Unfortunately I can not tell exactly what the problem was.

erikpolder avatar Feb 21 '17 08:02 erikpolder

Removed ios platform and all plugins. Re-installed ios platform and all plugins with no luck. I'm still facing same issue. Works in the simulator but not in a real device.

@epolder what capabilities did you enabled in xcode?

ramoncarreras avatar Feb 21 '17 10:02 ramoncarreras

+1 no found..

gbelmm avatar Feb 21 '17 16:02 gbelmm

Inter-App Audio and Background Audio. I do not know i Background Audio is needed. I did also see in my provision profile that Inter Audio was enabled on my certificate att developer.apple.com

erikpolder avatar Feb 21 '17 16:02 erikpolder