iOS Headset wire control questions about "remotecontrolreceivedwithevent" not implemented

Source: Internet
Author: User

First reprint several technical articles, to make the record

iOS Development Series--touch events, gesture recognition, shaking events, headphone wire control http://www.cnblogs.com/kenshincui/p/3950646.html

The Uiresponder of iOS framework research objects that can receive events (i)

http://blog.csdn.net/maojudong/article/details/7798138

iOS headphone cable Control http://blog.csdn.net/slinloss/article/details/18085145

Bottom start

The implementation of the above 3 articles reproduced in the article, you can refer to

Questions about the Remotecontrolreceivedwithevent method not executing:

1. Enable remote event reception ( using [[UIApplication sharedapplication] beginreceivingremotecontrolevents]; method).

2. The same requirement for UI controls must be the first responder (not required for view controller Uiviewcontroller or application UIApplication object monitoring).

3. The application must be the controller of the current audio, that is, the current audio playback program in the notification bar in iOS 7 must be our own development program.

The first two are not many, mainly speaking of the third, I will be the above "iOS headset wire control" This article in the code written in the

Appdelegate method, but does not execute the Remotecontrolreceivedwithevent method (Note: This method only can be triggered by the middle of headphones), and finally added a section of audio playback code, namely:

NSString *string = [[NSBundle mainbundle] pathforresource:@ "test" oftype:@ "MP3"];

Convert audio files to URL format

Nsurl *url = [Nsurl fileurlwithpath:string];

Initialize the audio class and add the playback file

Self.avaudioplayer = [[Avaudioplayer alloc] Initwithcontentsofurl:url Error:nil];

Pre-playback

[_avaudioplayer Preparetoplay]; And then press the middle key of the headset to trigger the Remotecontrolreceivedwithevent method.

If some students say do not want to use headphones control playback audio, want to control camera photo, my plan is to put an empty audio file, the Remotecontrolreceivedwithevent method triggered, and then write their own custom method. (here do not want to use headphones to control the playback of audio, but to achieve control of other custom methods, if you have different options, you can share the message, learn together)



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.