Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

themacster298

macrumors member
Original poster
Feb 20, 2011
55
0
well I have followed this tutorial showing you how to make a button that takes you to another view. But the only problem is that I don't know how to put audio when it takes you to the other view. Can someone please help or point to a tutorial. Any help is appreciated.
 
Last edited:
there is a viewDidLoad option in ur second view controller that ur loading.
U can load a sound there.
If u want to display a sound really when u click the button, just put it inside the void or the IBAction. Depends what ur code looks like.
 
I am having trouble with this. Can someone please add the code for the background music? heres the code:


This is the SecondViewController.h
Code:
#import <UIKit/UIKit.h>


@interface SecondViewController : UIViewController {

}

@end


This is the SecondViewController.m
Code:
#import "SecondViewController.h"


@implementation SecondViewController

/*
 // 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 {
    [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 {
    [super dealloc];
}


@end

P.S. If you want the code for the first view controller just ask
 
a button can only have one action(

Not true but that's another topic.

This is the same code used in the video but in the viewDidLoad method.
Code:
- (void)viewDidLoad {
	
	NSString *path = [[NSBundle mainBundle] pathForResource:@"bgmusic" ofType:@"m4a"];
	if(theAudio)[theAudio release];
	theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
	[theAudio play];
}
You can also put it in viewWillAppear like jnoxx said, or in a button action, or in a void method using performSelector.
 
I dont know if this is asking TO MUCH but I found a much simpler tutorial here. I did it without the back button. I tried what nickculbertson said with the second view and no sound came out. Can someone (I cant believe im going to type this again but) help?
 
I dont know if this is asking TO MUCH but I found a much simpler tutorial here. I did it without the back button. I tried what nickculbertson said with the second view and no sound came out. Can someone (I cant believe im going to type this again but) help?

They provided all the code, means u are doing something wrong..
Don't think they can help, have u tested on a device or not, and have u actually added the framework? instead of just the code.
it's couple lines of code, can't mess that up actually.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.