バックグラウンドミュージックを含めたいアプリがあります。音楽には次のコードを使用します。
.h: (フレームワークも追加しました)
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface ViewController : UIViewController
{
AVAudioPlayer *player;
}
.m:
- (void)viewDidAppear:(BOOL)animated {
NSURL *url = [[NSBundle mainBundle] URLForResource:@"song" withExtension:@"mp3"];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
player.numberOfLoops = -1;
[player play];
NSLog(@"playing music");
}
音楽ファイルのパスは間違いなく正しいです。アプリはクラッシュしませんが、音楽が聞こえません。
ところで、LogMessage (「音楽を再生中」) がデバッガーに表示されます。
何か案は?