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 07-30-2010, 06:06 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 81
Ammad is on a distinguished road
Default Background Music ??

Hello, I'm trying to play background music but it is not working.
</Edited>
I just wanna Know, does the simulator support the background music ? If there is a way then post some code or link.
<Edited/>
Can anyone please help me on this.

Thanks, Ammad.

Last edited by Ammad; 07-30-2010 at 06:24 PM.
Ammad is offline   Reply With Quote
Old 08-04-2010, 11:07 AM   #2 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 81
Ammad is on a distinguished road
Default

I guess no one knows....
Thanks anyways
Ammad is offline   Reply With Quote
Old 08-04-2010, 11:24 AM   #3 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 8
s8film40 is on a distinguished road
Default

This is what I did.

•Add AVFoundation.framework

•Add aif audio file to project

•.h File

Code:
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>



@interface FirstViewController : UIViewController {
	AVAudioPlayer *playBackAudio;
		
}

-(IBAction)playBackAudio;

@end
•.m File

Code:
#import <AVFoundation/AVAudioPlayer.h>



@implementation FirstViewController


-(IBAction)playBackAudio
{

	[playBackAudio play];
}



/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
 if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
 // Custom initialization
 }
 return self;
 }
 */


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	{
		NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/audio.aif", [[NSBundle mainBundle] resourcePath]]];
		
		NSError *error;
		playBackAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
		playBackAudio.volume = 0.1;
		playBackAudio.numberOfLoops = -1;
	}
	
	
		
    [super viewDidLoad];
}


/*
 // Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }
 */

- (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 {
	[playBackAudio release];
	    [super dealloc];
}


@end
You can change the settings for loop and volume. I'm pretty new to this my self so be careful with what I provided but it worked for me. You could also probably simplify it as I set this up to have a button to start it. You could just add the play command in the view did load. Hope this helps, good luck.
s8film40 is offline   Reply With Quote
Old 08-04-2010, 01:33 PM   #4 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 81
Ammad is on a distinguished road
Default

Quote:
Originally Posted by s8film40 View Post
This is what I did.

•Add AVFoundation.framework

•Add aif audio file to project

•.h File

Code:
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>



@interface FirstViewController : UIViewController {
	AVAudioPlayer *playBackAudio;
		
}

-(IBAction)playBackAudio;

@end
•.m File

Code:
#import <AVFoundation/AVAudioPlayer.h>



@implementation FirstViewController


-(IBAction)playBackAudio
{

	[playBackAudio play];
}



/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
 if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
 // Custom initialization
 }
 return self;
 }
 */


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	{
		NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/audio.aif", [[NSBundle mainBundle] resourcePath]]];
		
		NSError *error;
		playBackAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
		playBackAudio.volume = 0.1;
		playBackAudio.numberOfLoops = -1;
	}
	
	
		
    [super viewDidLoad];
}


/*
 // Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }
 */

- (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 {
	[playBackAudio release];
	    [super dealloc];
}


@end
You can change the settings for loop and volume. I'm pretty new to this my self so be careful with what I provided but it worked for me. You could also probably simplify it as I set this up to have a button to start it. You could just add the play command in the view did load. Hope this helps, good luck.
Can you please explain that when -(IBAction)playBackAudio is called ? because it's an IBAction then , when any button will be pressed it will be called, I changed it to (void).
and will it support the the .mp3 extension ? because i'm using .mp3 and it is not working...

Last edited by Ammad; 08-04-2010 at 02:04 PM.
Ammad is offline   Reply With Quote
Old 08-04-2010, 05:04 PM   #5 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 8
s8film40 is on a distinguished road
Default

I think you should be able to remove the ibaction and just put the play command in the viewdidload. I used aif, didn't try mp3.
s8film40 is offline   Reply With Quote
Old 08-05-2010, 02:12 PM   #6 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 81
Ammad is on a distinguished road
Default

yeah i did that , its working now , thanks for your help s8film40.

I also did it through threading like this:
- (void)viewDidLoad {
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(backgroundMusic object:nil];
[thread start];
...
...
...
}


-(void) backgroundMusic id)sender
{

NSLog(@"I'm in ");
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"backgroundMusic.mp3" ofType:nil];


// Convert the file path to a URL.
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath];




//Initialize the AVAudioPlayer.
audioPlayer = [[AVAudioPlayer alloc]
initWithContentsOfURL:fileURL error:nil];

// Preloads the buffer and prepares the audio for playing.
[audioPlayer prepareToPlay];

//audioPlayer.currentTime = 0;

[audioPlayer play];

[filePath release];
[fileURL release];
}

Last edited by Ammad; 08-05-2010 at 02:15 PM.
Ammad is offline   Reply With Quote
Old 08-05-2010, 02:18 PM   #7 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 81
Ammad is on a distinguished road
Default

hey, can u tell me how can I close any subscribed thread of mine ?
Ammad is offline   Reply With Quote
Old 08-05-2010, 02:24 PM   #8 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Long Beach, CA
Posts: 612
bytor99999 is on a distinguished road
Send a message via AIM to bytor99999 Send a message via Yahoo to bytor99999
Default

Quote:
Originally Posted by Ammad View Post
hey, can u tell me how can I close any subscribed thread of mine ?
Click "Quick Links above and there is a Subscribed Threads menu choice, you can manage them there

Mark
__________________
Perfect World Programming LLC
http://www.perfectworldprogramming.com

Please check out my apps.

TubeOrganizer
http://www.spritzlerapps.com/tube-organizer.html

Paper Clips
http://spritzlerapps.weebly.com/paper-clips.html
bytor99999 is offline   Reply With Quote
Reply

Bookmarks

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: 335
15 members and 320 guests
appservice, bignoggins, dermotos, Domele, EXOPTENDAELAX, guusleijsten, Hamad, heshiming, linkmx, Objective Zero, Paul Slocum, Rudy, Sloshmonster, teebee74
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,653
Threads: 94,115
Posts: 402,888
Top Poster: BrianSlick (7,990)
Welcome to our newest member, ohmniac
Powered by vBadvanced CMPS v3.1.0

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