Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-16-2010, 10:20 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2009
Location: London
Posts: 15
mrsaxon10 is on a distinguished road
Default sound will not play on the device

I have a very puzzling problem, which I really cannot work out what is going wrong.

Basically I am making an application that when a sound is made by someone will cause my application to display a random image and play a sound at the same time.

The puzzerling thing is this it works brilliantly in the simulator but does when I put it on my device the image will randomize but no sound will play. I have looked through the forums and tried to eliminate as many causes to the problem the sound file is a cif and I have made sure that my device volume is indeed on.

So the problem is nothing to do with the sound file format.

I have even tried testing out using code so that when I shake the device it will initiate the random image and the sound, this works perfectly on my device.

I think whatever is causing my sound not to play on the device has something to do with the code used to detect sound. But I cannot work out what exactly I have done wrong.

The code is below I hope someone can help


Code:
 #import "ScaryEyesViewController.h"

@implementation ScaryEyesViewController




-(IBAction) img1 {
	
	UIImage *img = [UIImage imageNamed:@"Image2.png"];
	[imageView setImage:img];
	
}




// -(IBAction) img2 {


//	int randomInt = arc4random()%3;

//		NSString *fileName = [NSString stringWithFormat:@"Image%d.png", randomInt];
//		UIImage *img = [UIImage imageNamed:fileName];
//		UIImageView *imageView = [[UIImageView alloc] initWithImage:img];







- (void)viewDidLoad {
	[super viewDidLoad];
	
	NSURL *url = [NSURL fileURLWithPath:@"/dev/null"];
	
	NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
							  [NSNumber numberWithFloat: 44100.0],                 AVSampleRateKey,
							  [NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
							  [NSNumber numberWithInt: 1],                         AVNumberOfChannelsKey,
							  [NSNumber numberWithInt: AVAudioQualityMax],         AVEncoderAudioQualityKey,
							  nil];
	
	NSError *error;
	
	recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
	
	if (recorder) {
		[recorder prepareToRecord];
		recorder.meteringEnabled = YES;
		[recorder record];
		levelTimer = [NSTimer scheduledTimerWithTimeInterval: 0.05 target: self selector: @selector(levelTimerCallback:) userInfo: nil repeats: YES];
		
		
		
	} else
		NSLog([error description]);	
}


- (void)levelTimerCallback:(NSTimer *)timer {
	[recorder updateMeters];
	
	const double ALPHA = 0.05;
	double peakPowerForChannel = pow(10, (0.05 * [recorder peakPowerForChannel:0]));
	lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults;	
	
	if (lowPassResults > 0.65)
		
		NSLog: [self micHadNoise];
	
	
	//// micHadNoise is essential
	
}

- (void) micHadNoise {
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	int randomInt = arc4random()%3;
	
	NSString *fileName = [NSString stringWithFormat:@"Image%d.png", randomInt];
	UIImage *randomImage = [UIImage imageNamed:fileName];
	
	
	
	imageView.image = randomImage;
	
	
	

	
	
	
//	NSString *urlAddress = [[NSBundle mainBundle] pathForResource:@"sound1" ofType: @"mp3"];
	
//	NSURL *url = [NSURL fileURLWithPath:urlAddress];
//	NSError *error;
	
//	AVAudioPlayer *audioPlayer = [[AVAudio alloc] initWithContentsOfURL:url error&error];
//	audioPlayer.numberOfLoops = 0;
//	if (audioPlayer == nil)
		
//	{
		
//		NSLog ([error description]);
//	}
//	else {
//		{
//			[audioPlayer play];
//	}

	
	
//	// 
	
	
	
//
	
	
	
	
	
	//NSString *path = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"mp3"];
//	AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
	
//	AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:&error];
	
	
	
//	theAudio.numberOfLoops = 1;
//	if (theAudio == nil)
	
	
	
	
	
	NSString *path = [[NSBundle mainBundle] pathForResource:@"farSound" ofType:@"caf"];
	AVAudioPlayer* theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
	
	theAudio.delegate = self;
	[theAudio play];
    
	

	
	
	
	
	
//	int randomNumber = arc4random() % 6;
//	NSString *tmpFileName = [[NSString alloc] initWithFormat:@"sound%d", randomNumber];
//	NSString *fileName2 = [[NSBundle mainBundle] pathForResource:tmpFileName ofType:@"mp3"];
	
//	SystemSoundID soundID;
//	AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:fileName2], &soundID);
//	AudioServicesPlaySystemSound (soundID);
	
	
	
	
	
	
	
	
}	





- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
	[super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[super dealloc];
}

@end
mrsaxon10 is offline   Reply With Quote
Reply

Bookmarks

Tags
detect, device, mic, simulator, sound

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 307
10 members and 297 guests
Abidullah, ajay123123, Fstuff, guusleijsten, HemiMG, jbro, newDev, pkIDSF, Sami Gh, Steven.C
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,113
Posts: 402,877
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:47 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0