RSS

Monthly Archives: January 2013

AVAudioSession + AVAudioPlayer Switch Between Internal and Loud Speaker

Below is code to switch between internal and loud speaker for AVAudioPlayer

 

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

                                      );

    

    Float64 sampleRate = 44100.0;

    dataSize = sizeof(sampleRate);

    result = AudioSessionSetProperty (

                                      kAudioSessionProperty_PreferredHardwareSampleRate,

                                      dataSize,

                                      &sampleRate

                                      );

    

    // 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

                                      );

    

    AudioSessionSetActive(YES);

}

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

                                      );

    

    Float64 sampleRate = 44100.0;

    dataSize = sizeof(sampleRate);

    result = AudioSessionSetProperty (

                                      kAudioSessionProperty_PreferredHardwareSampleRate,

                                      dataSize,

                                      &sampleRate

                                      );

    

    // Default to speakerphone if a headset isn’t plugged in.

    // Overriding the output audio route

    // The Trick is here

    

    UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_None;

    dataSize = sizeof(audioRouteOverride);

    AudioSessionSetProperty(

                            kAudioSessionProperty_OverrideAudioRoute,

                            dataSize,

                            &audioRouteOverride);

    

    

    AudioSessionSetActive(YES);

}

 
Leave a comment

Posted by on January 9, 2013 in Uncategorized

 

Code for Remove Layer (UIImageView) on Particular View

Hello Friends ,

below is code to remove with touch moved.

– (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

if(eraseOn == TRUE)
{
UITouch *touch = [touches anyObject];
lastTouch = [touch locationInView:self.drawImage];

}else{
/*
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
self.drawImage.center = location; */
}
}

– (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

if(eraseOn == TRUE){
UITouch *touch = [touches anyObject];
currentTouch = [touch locationInView:self.drawImage];
CGFloat brushSize = 5;
CGColorRef strokeColor = [UIColor whiteColor].CGColor;
UIGraphicsBeginImageContext(self.drawImage.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
[self.drawImage.image drawInRect:CGRectMake(0, 0, self.drawImage.frame.size.width, self.drawImage.frame.size.height)];
CGContextSetLineCap(context, kCGLineCapRound);
CGContextSetLineWidth(context, brushSize);
CGContextSetStrokeColorWithColor(context, strokeColor);
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextBeginPath(context);
CGContextMoveToPoint(context, lastTouch.x, lastTouch.y);
CGContextAddLineToPoint(context, currentTouch.x, currentTouch.y);
CGContextStrokePath(context);
self.drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
lastTouch = [touch locationInView:self.drawImage];
}
else {

// [self touchesBegan:touches withEvent:event];
}

}

– (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

}

And at below Link u can request for demo example ( how to integrate tutorial )

DrawView

 
Leave a comment

Posted by on January 1, 2013 in Uncategorized