Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Is there a way to respond to clicks from headphone buttons ??

fm.produktionsfm.produktions Posts: 74Registered Users
edited May 2011 in iPhone SDK Development
Im guess that the answer is no, but i just want to double check.

So is there any way to respond to the volume +/- or pause/play buttons on headphones ??
Post edited by fm.produktions on
***<u>Apps</u>***<br />
<br />
<a href="http://itunes.apple.com/us/app/drudge2go/id367224031?mt=8" target="_blank">Drudge 2 Go</a> for drudgereport.com on the iPhone

Replies

  • fm.produktionsfm.produktions Posts: 74Registered Users
    edited April 2010
    Ok, so from what i saw at the keynote for OS 4.0 this is possible

    it specifically says that apis for 'ipod remote controls'

    YES !!
    ***<u>Apps</u>***<br />
    <br />
    <a href="http://itunes.apple.com/us/app/drudge2go/id367224031?mt=8" target="_blank">Drudge 2 Go</a> for drudgereport.com on the iPhone
  • chewchew Posts: 8New Users
    edited August 2010
    Did you have any success with this?

    I would love to control my custom video recorder with the remote :)
    Ok, so from what i saw at the keynote for OS 4.0 this is possible

    it specifically says that apis for 'ipod remote controls'

    YES !!
  • coullscoulls I'm a Brit-pat, currently in Canada.Posts: 185Registered Users @ @
    edited August 2010
    Hi all,

    This is possible: You want to do three things:
    1. Edit your info.plist to stipulate that you do audio (UIBackgroundModes) in the background as well as foreground.
    2. Implement this function:
    - (void)remoteControlReceivedWithEvent:(UIEvent *)theEvent 
    {
    	if (theEvent.type == UIEventTypeRemoteControl) {
            switch(theEvent.subtype) {
    		case UIEventSubtypeRemoteControlTogglePlayPause:
    //Insert code
    
                case UIEventSubtypeRemoteControlPlay:
    				//Insert code
    				break;
                case UIEventSubtypeRemoteControlPause:
    				// Insert code
                    break;
                case UIEventSubtypeRemoteControlStop:
    				//Insert code.
                    break;
                default:
                    return;
            }
        }
    }
    

    ...obviously, replace the "//insert code" with whatever functionality is relevent in your app.

    Finally, in order for that above function to be called, insert this in your viewDidAppear event:
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
    	if ([self canBecomeFirstResponder]) {
    		[self becomeFirstResponder];
    	}
    

    Cheers,

    Coulls
  • chewchew Posts: 8New Users
    edited August 2010
    Thanks Coulls !

    When editing the info.plist i cannot see any UIBackgroundModes. Can you explain with a few more details how to edit the file properly?
  • chewchew Posts: 8New Users
    edited August 2010
    I cannot make the view controller to become the first responder.
    if ([self canBecomeFirstResponder]) {
    		[self becomeFirstResponder];
    } 
    
    NSLog(@"First Responder - %d", [self isFirstResponder]);
    

    It gives me a 0.

    Sorry for all the questions, but this whole iPhone sdk is a bit tricky to learn ;)
  • coullscoulls I'm a Brit-pat, currently in Canada.Posts: 185Registered Users @ @
    edited August 2010
    chew wrote: »
    Thanks Coulls !

    When editing the info.plist i cannot see any UIBackgroundModes. Can you explain with a few more details how to edit the file properly?

    There's one of two ways to do this, depending on how recent the app is. In both cases, add a new line to your PLIST file.

    If recent, add the new line, and select "Required Background Modes". In the "Item 0" that appears under/next to it, select "App plays audio".

    If not recent, add the new line and type "UIBackgroundModes". In the "Item 0" put "audio".

    Hope that helps!

    Cheers,

    Coulls
  • coullscoulls I'm a Brit-pat, currently in Canada.Posts: 185Registered Users @ @
    edited August 2010
    chew wrote: »
    I cannot make the view controller to become the first responder.

    If you get that issue, just override it. Paste this into your view's .m file, and it'll work:
    - (BOOL)canBecomeFirstResponder
    {
    	return YES;
    }
    

    Cheers,

    Coulls
  • chewchew Posts: 8New Users
    edited August 2010
    Thanks a lot!

    If i ad a AVAudioPlayer object i can detect the events from the remote, but only after the AVAudioPlayer has started the actual playback of a MP3. Even if i have initialized the player i cannot track the clicks before playing the MP3.

    I could somehow have an small soundfile looping in the background of my app all the time - but that would not be very pretty. Im not planning on having any audio in my app, just video recording/playback.

    Do you know if its possible to work with the UIEventTypeRemoteControl without playing audio?

    Another alternative is to access the serial port somehow and make an external controller with Arduino - but after searching online it seems to be a pretty complex task :rolleyes:
  • ToMToM Posts: 101Registered Users
    edited August 2010
    chew wrote: »
    Thanks a lot!

    If i ad a AVAudioPlayer object i can detect the events from the remote, but only after the AVAudioPlayer has started the actual playback of a MP3. Even if i have initialized the player i cannot track the clicks before playing the MP3.

    I could somehow have an small soundfile looping in the background of my app all the time - but that would not be very pretty. Im not planning on having any audio in my app, just video recording/playback.

    Do you know if its possible to work with the UIEventTypeRemoteControl without playing audio?

    Another alternative is to access the serial port somehow and make an external controller with Arduino - but after searching online it seems to be a pretty complex task :rolleyes:

    Just add a check to see whether an mp3 has been initialized already or not inside the code for the buttons, and if it hasn't, initialize it there.
  • chewchew Posts: 8New Users
    edited August 2010
    ToM wrote: »
    Just add a check to see whether an mp3 has been initialized already or not inside the code for the buttons, and if it hasn't, initialize it there.

    Thanks ToM!

    That does the job :)
  • Fedcis09Fedcis09 Posts: 34Registered Users
    edited May 2011
    chew wrote: »
    Thanks ToM!

    That does the job :)

    Hi. Would you mind taking a look at my code? I have followed your details so far, but i still am not getting it to snap a photo.
    - (void)remoteControlReceivedWithEvent:(UIEvent *)theEvent 
    {
    	if (theEvent.type == UIEventTypeRemoteControl) {
            switch(theEvent.subtype) {
            //    case UIEventSubtypeRemoteControlTogglePlayPause:
                    //Insert code
           //         [cpicker takephoto];
                    
                case UIEventSubtypeRemoteControlPlay:
    				//Insert code
                    (cpicker.cameraCaptureMode==UIImagePickerControllerCameraCaptureModePhoto);
                        [cpicker takePicture];
                    
    				break;
                case UIEventSubtypeRemoteControlPause:
    				// Insert code
                    [cpicker takephoto];
                    break;
              //  case UIEventSubtypeRemoteControlStop:
    				//Insert code.
            //        break;
                default:
                    return;
            }
        }
    }
    
    id386533720?mt=8
Sign In or Register to comment.