Preety
Preety

Reputation: 31

Divert iPhone's volume control to app when app is running

I am using AVSpeechSynthesizer to convert text to speech in my app. This app reads the text after certain intervals.

Whenever the app is speaking, if I press the device's volume buttons, it changes the volume of the current speech as well as the media volume of the device. (i.e. if any music is playing and AVSpeechSynthesizer starts speaking, music pauses and it resumes as soon the speech is over. So meanwhile if I change the volume, it gets applied to the music player's volume also.)

So is it possible force the volume control buttons to change the app volume alone when app is running?

PS. The app is for iOS 8.0+.

Any help would be appreciated.

Thanks.

Upvotes: 3

Views: 499

Answers (2)

some_id
some_id

Reputation: 29896

No, you cannot intercept the hardware volume and adjust only your app volume, it's not designed for that. The OS would then need to track all volumes per apps, and e.g. what if you had AudioBus running with multiple app audio streams chained together.

You need to rethink your problem. To control your app's volume, add a volume control to the UI.

Upvotes: 1

As i understand you want to control the volume separately in the App without affecting Device volume. It sounds difficult & i don't think its achievable.

There is an option you can try out here i have explained:

  • Store both Device volume & App volume values in the App
  • While using App volume control don't change App volume, just store that value in App volume
  • Now while playing anything in the App change volume with the App Volume value
  • Once you finish playing just change volume with Device volume value

Important Note:

  • This is pure logical way to control sound in the App without affecting system volume. You will not find such way mentioned anywhere in the App docs.

EDIT:

If you want to make App volume as it is while pressing device volume button. You can try out this steps. It looks not tested but might work.

  • Check if in the App if you can constantly check device volume value updated.
  • If you are getting notified for device volume change some how in the app. You can reset again it from the App at the same time when it changed from device volume button.

I hope it will help you.

Upvotes: 0

Related Questions