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

iOS: music controls with TTS? #62

Open
givethanks1 opened this issue May 22, 2021 · 2 comments
Open

iOS: music controls with TTS? #62

givethanks1 opened this issue May 22, 2021 · 2 comments

Comments

@givethanks1
Copy link

givethanks1 commented May 22, 2021

Hi,

Excellent plugin, thank you. I'm using it for an Android text-to-speech TTS project (read text from a page - and the user can play/stop the reading using the MusicControls) and it works perfectly.

On iOS it does not seem to load the music controls when the text to speech reading is active (audio can be heard). Here is some sample code to illustrate how I'm using it. My iOS device is an iPhone SE with iOS 13.4.1 (in case that's helpful). I have also tried with iPhone 8 XCode simulator running iOS 14.4.
** EDIT: the controls are launched on the simulator for iPhone 8 with iOS 14.4 (but not on the device with iOS 13.4.1), once i removed the following lines from the config.xml file. Oddly enough it does not fire the following functions: onMusicControlsCreateSuccess() or onMusicControlsCreateFailure() on either platform**

        <config-file target="*-Info.plist" parent="UIBackgroundModes">
          <array>
            <string>audio</string>
          </array>
        </config-file>

Using the code below, neither the onMusicControlsCreateSuccess() nor the onMusicControlsCreateFailure() seem to fire.

I'm not sure if the issue is with TTS + Music Controls use or if I'm doing something wrong.
Note: have also installed your plugin from https://github.com/ghenry22/cordova-plugin-background-mode on iOS

  • and enabled Xcode's background mode for audio

Any advice is welcome. Thanks.

...
// User has clicked a button on the app to read the screen content
//    reading begins successfully and can be heard on iOS  & android. 
// Next we want to fire up the controls to let the user stop the playing from the home screen / notification area
//    this works on Android but not for iOS

let musicControlOptions = {
	track: voiceTrack,
	artist: voiceArtist,
	album: voiceAlbum,
	dismissable : true,
	hasPrev: true,
	hasNext: true,
	hasClose: true,
	isPlaying: false
};
if (vDevice === 'ios' || vDevice === 'android') { // the vDevice variables are set earlier             
      if (vDevice === 'ios'){
           let isBGModeActive = cordova.plugins.backgroundMode.isActive();
           if (isBGModeActive === false) {
                 cordova.plugins.backgroundMode.enable();
             }
             console.log('bgmode: ', isBGModeActive); // this is logged properly, gives true if in background
       }
                 
        MusicControls.create(musicControlOptions, onMusicControlsCreateSuccess, onMusicControlsCreateFailure);

// other code here  
}

function onMusicControlsCreateFailure() {
        console.log('could not create controls'); // this is not logged, appears not to fire for iOS
}
function onMusicControlsCreateSuccess() {
        MusicControls.updateIsPlaying(true);
        console.log('success creating controls'); // this is not logged, appears not to fire for iOS
  // more code to handle player button events

        MusicControls.subscribe(events);
        MusicControls.listen();
}

```
@currim
Copy link

currim commented May 25, 2021

You may want to try playing an "empty" music track in the background while you do TTS?

@givethanks1
Copy link
Author

You may want to try playing an "empty" music track in the background while you do TTS?

I have not tried that. Would prefer not to add extra code (e.g., for a regular media player) and permissions, unless necessary.

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

2 participants