mp3 파일을 재생해야하는 앱을 제작하고 있습니다. 그 문제에 관해서, 나는 다른 사람들이 읽고있는 표시를 따라 AVAudioPlayer를 사용하고있다. 하지만 내 문제는 코드 (iOS 벨소리 첨부)가 iOS 시뮬레이터에서 작동하지만 내 iPhone에서 사용하려고하면 작동하지 않는다는 것입니다. 여러분 중 누구도이 문제를 해결할 수 있기를 바랍니다. 발행물.AVAudioPlayer는 iOS 시뮬레이터에서 재생되지만 iPhone에서는 재생되지 않습니다.
파일 .H :
#import "UIKit/UIKit.h"
#import "AVFoundation/AVFoundation.h"
@interface ViewController : UIViewController <AVAudioPlayerDelegate>
@property (strong, nonatomic) AVAudioPlayer *player;
@end
파일하는 .m은 : 오디오 (또는 이미지) 시뮬레이터 (도시) 일 때
#import "ViewController.h"
@implementation ViewController
@synthesize player;
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"beep_7" ofType:@"mp3"];
NSLog(@"Audio path: %@", soundFilePath);
NSError *error;
self.player =[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:soundFilePath] error:&error];
if (error) {
NSLog(@"Error in audioPlayer: %@",[error localizedDescription]);
}
else {
[self.player setDelegate:self];
[self.player setNumberOfLoops:3]; //just to make sure it is playing my file several times
self.player.volume = 1.0f;
if([self.player prepareToPlay]) //It is always ready to play
NSLog(@"It is ready to play");
else
NSLog(@"It is NOT ready to play ");
if([self.player play]) //It is always playing
NSLog(@"It should be playing");
else
NSLog(@"An error happened");
}
}
-(void)audioPlayerDecodeErrorDidOccur: (AVAudioPlayer *)player error:(NSError *)error {
NSLog(@"audioPlayerDecodeErrorDidOccur -> Error in audioPlayer: %@",[error localizedDescription]);
}
-(void)audioPlayerDidFinishPlaying: (AVAudioPlayer *)player successfully:(BOOL)flag{
NSLog(@"audioPlayerDidFinishPlaying");
}
-(void)audioPlayerBeginInterruption:(AVAudioPlayer *)player{
NSLog(@"audioPlayerBeginInterruption");
}
-(void)audioPlayerEndInterruption:(AVAudioPlayer *)player{
NSLog(@"audioPlayerEndInterruption");
}
@end
고마워, 나는 물리적 인 음소거 botton을 쳤다. 그리고 나는 그것에 관해 실현을 didnt한다! 감사 – rubrin