How to get the device volume values to my app - iphone

I am using volume in my app using MPMusicPlayerController with plus and minus buttons for increasing and decreasing the volume(for increasing and decreasing indicates through horizontal images). While pressing the buttons(user defined) volume works good, if i use the device volume button volume is adjusting but its not syncing with app volumes button, i.e the images for increasing and decreasing are not getting called.
Simply, how can get the device volume values to my app ?

You can find all the answers on this thread. It also has some example code. Look at Sandy's answer!

Related

Increase volume programmatically

i want in my app to increase and decrease the app volume programmatically from the code and not to use MPVolumeView.
You cannot change the volume programmatically, and that's a deliberate design choice. Imagine an app that constantly sets the volume to the highest level, that would not only be annoying but could even damage your ears if you're wearing in-ear headphones.
You should show an MPVolumeView to the user so he can change the volume himself. You can walk its subview hierarchy and search for the UISlider and adjust its appearance like with any normal UISlider. This way you can adapt the MPVolumeView to your app design.
Officially: You can't.
If you really want to do so, link against Celestial.framework and use its controllers to change the volume - that is how SpringBoard and friends do it. I don't remember how to do it, but with a bit of research you should be able to find the answer. This will get your app rejected. If you're developing for a jailbroken device, this is the way to go.
If you want to go deeper you can do it via the vTable of the appropriate CoreAudio service. You also need Celestial.framework for that. And if you want to go even deeper, kill mediaserver and make your own implementation which should occupy your for the next few months.

Images showing in simulator but not on the iPhone device

So when I run the application from the device the pictures show up and everything works great. However, when I move to the device I run in about 10 out of 38 pictures that don't show up. I am pulling the names for the images from an sqlite database and I already checked and the names are correct, case and everything. I checked the bundle and the images are correctly in there.
Does memory play into effect in this? I am not really sure what else could cause this to happen??
Thanks!
Solution:
The files somehow were not saved properly and were unable to be opened by say photoshop or paint even. So with the files not being able to be open they weren't showing up... Thanks for the help everyone!
First thing to check is the case of the strings you're using to refer to the resources. The iPhone is case sensitive, but the simulator is not.
Oops, just seen that you checked the case. Better log all your UIImage creation calls then!
The simulator accepts a wider range of image formats. Sometimes you had a specific file type that the device cannot display. Double check the 10 files looking for some difference from the others ones.
Yes, memory absolutely plays into this. Check your UIImage creation calls and make sure they dont return empty. Also, check to see if youre getting memory warnings in the console window.
Generally, if in-memory size was the culprit, your application would crash with a low memory error on the device. However, it seems like the images just don't display.
One other thing that can be going wrong is the size of the images. UIViews on the iPhone can only have dimensions smaller than the maximum texture size supported by the GPU. Apple states that this is 1024 x 1024, but I've found it to be more like 2048 x 2048 on even the original model iPhone. You may be creating a view for some of these images that exceeds this size in one dimension, but your Mac has a larger maximum texture size on its GPU and so it displays fine in the Simulator.
Apparently the iPhone caches the launch screens. So in my case, I had to reboot my iPhone before being able to see the image.

How to solve Memory Warning Level-1,then Memory Warning Level-2?

I am using apple standard code for scrolling+zooming+paging after 10 image scrolling and paging my console gives Memory Warning Level-1,Then Memory Warning Level-2 and then crash how can i stop crash my application?Please help me.I have taken this code from http://developer.apple.com/library/ios/#samplecode/PhotoScroller/Introduction/Intro.html
Did you implement the -(void)didReceiveMemoryWarning ? You can release every images that you don't use at this moment.
Keeping all images in an array will prevent you of doing this. Instead, you should create a method that gives you the right image based on its index (like an array) but that manages a cache (i.e. using an array) that you can clean when memory warnings are issued. Also I don't know this sample project by heart but I guess that they use only three controls to display image on the left, current image and image on the left. If not, be sure that other views are released when not useful for display.
It seems the images you use is of greater size.Try to reduce the pixel size and use it.
All the Best.
Each big image must be treated as a set of tiles and load data from the ONLY tile or set of tiles which is / are currently being displayed on the screen.
I dont know exactly how this works but you can google for it, I guess.

iPhone volume changed event for volume already max

I'm using
AudioSessionAddPropertyListener(kAudioSessionProperty_CurrentHardwareOutputVolume,
audioVolumeChangeListenerCallback, self);
to detect volume changes so i can take a picture with the volume rockers but if the phone is already at 100% i don't get an event. Is there a way to detect volume rocker pressed when the volume doesn't actually change?
I found a good answer with full source code here:
When the user presses the volume buttons in your app, you don’t want
the system volume to change. It would suck to have them taking
pictures and turn up their ringtone volume all the way or something.
So how do I pull that off? This is pretty hacky but it works.
Well you could set the volume lower after you've registered a volume button press to take a picture. That way the volume never reaches 100% and you can continue getting callbacks. Make sure to lower the volume by more than the volume changes in a single press of the volume button.
You will want to be careful to use some method to prevent receiving multiple notifications at once, but you are likely already doing that if you only take one photo per "button press".
I think I'm going to implement this feature (didn't think it was needed, but now I like the idea) in my app, and I'll post some code if I get it working, let me know if you get yours working as well.

Standard way of adding Sound to an iPhone app (global volume indicator)

I have an app with various views. The main menu does not have any sounds, but the next views play sounds using the AVAudioPlayer Class.
So when someone launches the app and is in the main menu, if he changes the volume on his device, he actually changes the "Ringer" volume. If he proceeds to the other views (where we have sound), when he changes the volume on the device he changes the volume of the game, not the ringer.
Is there a way to have them change the app volume every time, from the beginning of my app, before I create any instances of AVAudioPlayer??
(some misunderstood that. What I mean is that square that the OS overlays on the screen every time you press the volume buttons. If you are on the home screen, you change the "Ringer". When you are in a game, you change the app's volume).
PS:
I initialize the AudioSession on my main menu but that doesn't make any difference.
The only hack i have found is to actually create an instance of AVAudioPlayer on my main menu and set it to "preparedToPlay". But I would rather hear what the others are doing (a proper solution).
The volume buttons will affect the ringer volume if your application isn't currently playing audio. Some apps work around this by playing a silent audio file. Carefully consider how you do this, though - is adjusting the apps volume when it's not actually playing something actually useful?
It seems like you ought to be able to do what you want by modifying the AudioSession properties, but I haven't figured out how (if it is possible).
There is a class called MPVolumeView which is used for this purpose. Here's a good link explaining the use of MPVolumeView
Adding MPVolumeView to your view will create an iPod-like volume slider which will change when you change the volume using the rocker buttons. The value will automatically be used by the AVAudioPlayer class.
To keep track of volume without the slider
The rocker buttons by default change the app volume only when some audio is playing. There is a workaround to this problem - this SO thread discusses some workarounds.