大家好, 請看下面的代碼,我希望能夠停止聲音時,單擊同一個按鈕,另一個按鈕被單擊,甚至當返回到主屏幕。不知道在這裏做什麼,在Xcode中停止聲音
FoxViewController.m
#import "FoxViewController.h"
#import <AVFoundation/AVAudioPlayer.h>
AVAudioPlayer *newPlayer_Fox;
@interface FoxViewController()
@end
@implementation FoxViewController
-(IBAction) Fox;
{
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource: @"new"ofType: @"mp3"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL error: nil];
[newPlayer play];
}
- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
FoxViewController.h
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>
AVAudioPlayer *newPlayer;
@interface FoxViewController : UIViewController
-(IBAction)Fox;
@end
你的幫助深表感謝,賈斯汀。
thankyou :)感謝您的幫助 –