0
我有一个声音播放按钮从主视图控制器工作正常。在下一个视图控制器上,我还希望在按下的按钮上播放声音,但是我没有收到任何声音。我将这两个.h和.m文件设置为相同。我的问题是什么?感谢您的任何帮助。AudioPlayer没有在第二个视图控制器上播放
我.m文件:
#import "AboutView.h"
#import <AVFoundation/AVFoundation.h>
#import <CoreAudio/CoreAudioTypes.h>
@interface AboutView()
@end
@implementation AboutView
@synthesize support;
@synthesize facebook;
@synthesize kmbdev;
@synthesize back;
@synthesize player2;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNi{
if (self) {
// Custom initialization
}
return self;
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource: @"sound1" ofType: @"wav"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
self.player2 = [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL error: NULL];
player2.volume = .5;
[player2 prepareToPlay];
}
我.h文件中:
#import "ViewController.h"
#import <MessageUI/MessageUI.h>
#import <AVFoundation/AVFoundation.h>
#import <CoreAudio/CoreAudioTypes.h>
@class ViewController;
@interface AboutView : UIViewController <MFMailComposeViewControllerDelegate, AVAudioPlayerDelegate>{
AVAudioPlayer *player2;
}
@property (strong, nonatomic) IBOutlet UIButton *back;
- (IBAction)back:(id)sender;
@property (strong, nonatomic) IBOutlet UIButton *support;
@property (strong, nonatomic) IBOutlet UIButton *facebook;
@property (strong, nonatomic) IBOutlet UIButton *kmbdev;
- (IBAction)email:(id)sender;
@property (strong, nonatomic) AVAudioPlayer *player2;
@end
我有[player2播放];在我为主视图控制器做准备时,我准备了segue和IBaction。
你开发iOS或OSX? –
我正在为iOS开发。 – kmb