Audio playback after iOS recording is small, audiosessioninitialize Failed,audioqueuestart failed (-50)

Source: Internet
Author: User

Method 1:
UInt32 Audioroute = Kaudiosessionoverrideaudioroute_speaker; Audiosessionsetproperty (Kaudiosessionproperty_overrideaudioroute, sizeof (Audioroute), &audioroute);

Method 2:
[[Avaudiosession sharedinstance] Setcategory:avaudiosessioncategoryplayback Error:nil];

Solution for Audiosessioninitialize Fail ( dispatch_once_t) Solution Audioqueuestart failed (-50)
The
audiosessioninitialize can be executed multiple times, but Audiosessioninterruptionlistener can only be set once, which means that the interrupt callback method is a static method, Once the initialization is successful, all interrupts will be called back to this method, even though the next time the audiosessioninitialize is invoked again and another static method is passed as a parameter, it will be recalled to the first set method when the interrupt arrives.   This scenario is not uncommon, such as your app , and of course you can't know which feature the user will call first. So you have to call the Audiosessioninitialize registration interrupt method in the playback and recording module, but the final interrupt callback will only function in the module of the earlier registration, the egg hurts ... So the best way to use the audiosession is to generate a class that manages it individually, receives the interrupt callback and sends a custom interrupt notification, receives the notification in the module that needs to use the audiosession, and takes the appropriate action. Excerpt from: http://www.cocoachina.com/industry/20140717/9162.html
Static dispatch_once_t Oncetoken;    __block Osstatus error;        Dispatch_once (&oncetoken, ^{error = audiosessioninitialize (null, NULL, nil, (__bridge void*) self); if (error) printf ("Error INITIALIZING AUDIO session!        %d\n ", (int) error);             else {UInt32 category = Kaudiosessioncategory_playandrecord;                         Error = Audiosessionsetproperty (kaudiosessionproperty_audiocategory, sizeof (category), &category);                         Audiosessionsetactive (TRUE);                         if (error) printf ("couldn ' t set audio category!"); Error = Audiosessionaddpropertylistener (Kaudiosessionproperty_audioroutechange, Proplistener, (__bridge void*) self)            ; if (error) printf ("Error ADDING AUDIO SESSION PROP listener!            %d\n ", (int) error);            UInt32 inputavailable = 0;                         UInt32 size = sizeof (inputavailable); We don't want to allow recording if input are not availabLe error = audiosessiongetproperty (kaudiosessionproperty_audioinputavailable, &size, &inputavailable); if (error) printf ("Error GETTING INPUT availability!                                      %d\n ", (int) error); We also need to listen to see if input availability changes error = Audiosessionaddpropertylistener (kaudiose            Ssionproperty_audioinputavailable, Proplistener, (__bridge void*) self); if (error) printf ("Error ADDING AUDIO SESSION PROP listener!                         %d\n ", (int) error);            Error = Audiosessionsetactive (true);                         if (error) printf ("Audiosessionsetactive (true) failed");            UInt32 Audioroute = Kaudiosessionoverrideaudioroute_speaker;            Error = Audiosessionsetproperty (kaudiosessionproperty_overrideaudioroute, sizeof (Audioroute), &audioroute);        if (error) printf ("Audiosessionsetproperty (Audioroute_speaker) failed"); }             });

Audio playback after iOS recording is small, audiosessioninitialize Failed,audioqueuestart failed (-50)

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.