AVAudioPlayer via Speakers

Posted by Mark on Stack Overflow See other posts from Stack Overflow or by Mark
Published on 2010-04-18T02:12:29Z Indexed on 2010/04/18 2:23 UTC
Read the original article Hit count: 411

Filed under:
|
|

I got the following code:

- (id)init {
    if (self = [super init]) {
        UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
        AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);    

        UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
        AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);

        [[AVAudioSession sharedInstance] setDelegate:self];
        [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
        [[AVAudioSession sharedInstance] setActive:YES error:nil];
    }
    return self;
}

But somehow the sound does not want to come out of the speakers, can someone see what I am doing wrong?

The code I use for playing is:

AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFilePathURL error:nil];
[player prepareToPlay];
[player setVolume:1.0];
[player play];

© Stack Overflow or respective owner

Related posts about iphone

Related posts about speaker

  • Android app not releasing mic/speaker

    as seen on Stack Overflow - Search for 'Stack Overflow'
    I have a VOIP application that blocks the microphone and speaker after using it! Steps to reproduce: Place a call on 4G (both mic and speaker work) Place a call on app (both mic and speaker work) Place a call on 4G (Neither mic nor speaker work) Steps to fix mic and speaker: Open applications… >>> More

  • PASS Call for Speakers

    as seen on SQL Blog - Search for 'SQL Blog'
    It's that time again - the PASS Summit 2010 (Seattle Nov 8-11) Call for Speakers is now open and accepting abstracts until June 5 th . personally, I'm on a pattern that on odd years I present what I'm excited about, and on even years I try try to proesent what I expect other are jazzed about, which… >>> More

  • A little on speaking and evaluations...

    as seen on SQL Blog - Search for 'SQL Blog'
    Buck Woody ( blog | twitter ) just published a great post on session evaluations , and a lot of his points hit home for me. The premise is that the evaluations are not really meant for the attendee or the event organizers, but so that the speaker can get better and make the next session better. In… >>> More

  • Getting the PC speaker to beep

    as seen on Ask Ubuntu - Search for 'Ask Ubuntu'
    There has been much written on getting the beep sound from Ubuntu releases over the years. Example: fixing the beep My needs are slightly different in that I do not want to ensure sound card beeps are functioning. Instead, I want PC speaker beeps, the kind produced by the original built-in speaker… >>> More

  • No sound on laptop speakers on an Acer Aspire 6920

    as seen on Ask Ubuntu - Search for 'Ask Ubuntu'
    Computer: Acer Aspire 6920 Card: HDA Intel Chip: Realtek ALC889 My problem is that the laptop build-in speakers don't play any sound. When i plug in my headphones the sound works normally, the same goes with external speakers. Those work normally like the headphones. The profile in the Sound settings… >>> More