Advertise here




Advertise here

Howdy, Stranger!

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

Sign In with Google Sign In with OpenID

Badges

Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Husam

About

Username
Husam
Joined
Visits
92
Last Active
Roles
New Users
Points
3
Badges
1
Posts
2
Location
Iraq
  • Sound play through Upper Speaker

    I have the answer :

    just make a toggle button to switch between these two methods

    EnableSpeakerPhone()

    void EnableSpeakerPhone ()
    {
    UInt32 dataSize = sizeof(CFStringRef);
    CFStringRef currentRoute = NULL;
    OSStatus result = noErr;

    AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &dataSize, &currentRoute);

    // Set the category to use the speakers and microphone.
    UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord;
    result = AudioSessionSetProperty (
    kAudioSessionProperty_AudioCategory,
    sizeof (sessionCategory),
    &sessionCategory
    );
    assert(result == kAudioSessionNoError);

    Float64 sampleRate = 44100.0;
    dataSize = sizeof(sampleRate);
    result = AudioSessionSetProperty (
    kAudioSessionProperty_PreferredHardwareSampleRate,
    dataSize,
    &sampleRate
    );
    assert(result == kAudioSessionNoError);

    // Default to speakerphone if a headset isn't plugged in.
    UInt32 route = kAudioSessionOverrideAudioRoute_Speaker;
    dataSize = sizeof(route);
    result = AudioSessionSetProperty (
    // This requires iPhone OS 3.1
    kAudioSessionProperty_OverrideCategoryDefaultToSpeaker,
    dataSize,
    &route
    );
    assert(result == kAudioSessionNoError);

    AudioSessionSetActive(YES);
    }
    DisableSpeakerPhone()

    void DisableSpeakerPhone ()
    {
    UInt32 dataSize = sizeof(CFStringRef);
    CFStringRef currentRoute = NULL;
    OSStatus result = noErr;

    AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &dataSize, &currentRoute);

    // Set the category to use the speakers and microphone.
    UInt32 sessionCategory = kAudioSessionCategory_PlayAndRecord;
    result = AudioSessionSetProperty (
    kAudioSessionProperty_AudioCategory,
    sizeof (sessionCategory),
    &sessionCategory
    );
    assert(result == kAudioSessionNoError);

    Float64 sampleRate = 44100.0;
    dataSize = sizeof(sampleRate);
    result = AudioSessionSetProperty (
    kAudioSessionProperty_PreferredHardwareSampleRate,
    dataSize,
    &sampleRate
    );
    assert(result == kAudioSessionNoError);

    // Default to speakerphone if a headset isn't plugged in.
    // Overriding the output audio route

    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_None;
    dataSize = sizeof(audioRouteOverride);
    AudioSessionSetProperty(
    kAudioSessionProperty_OverrideAudioRoute,
    dataSize,
    &audioRouteOverride);

    assert(result == kAudioSessionNoError);

    AudioSessionSetActive(YES);
    }
    1- I think the first method (EnableSpeakerPhone) u already have it ...
    2-To ensure that the upper speaker is the default audio output ... add this code when u (SetupVoiceSession)

    //if the device not an iPhone Enable speaker
    if (![[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel:+11111"]]) {
    EnableSpeakerPhone();
    }
    3- Don't forget to dim the display when using the upper speaker (Use ProximitySensor)

    //Enable ProximitySensor if the device is iPhone
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel:+11111"]]){
    device = [UIDevice currentDevice];
    device.proximityMonitoringEnabled = YES;
    if (device.proximityMonitoringEnabled == YES)
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(proximityChanged:) name:@"UIDeviceProximityStateDidChangeNotification" object:device];
    }
    Congratulations .. u have done

    Finally ,, sorry for my bad english (^_^) cause I'm from Iraq .
    ad1269