私はいくつかの音楽を演奏するuitabviewcontrollerのiosアプリで作業しています。私は各タブのviewcontrollerがそれ自身のオーディオプレーヤーを作成する必要はありません。私は単一のオーディオプレーヤーを持ち、すべてのビューコントローラーがそれを共有したいと思っています。ios single AVAudioPlayer
ので、私は、このクラスのインスタンスを1つだけ作成したいとすべての私のviewcontrollersがそれを共有し、
#import <AVFoundation/AVFoundation.h>
@interface player : NSObject {
AVAudioPlayer *theMainAudio;
}
-(void)playSong:(NSString *)songName;
@end
を曲のURLでavaudioplayerを開始し、歌を果たしているでしょうプレーヤーと呼ばれるクラスを作成しました。私は.Mファイルに
@interface AppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
player *theMainPlayer;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@property (nonatomic, retain) player *theMainPlayer;
@end
、
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//some other stuff here....
theMainPlayer = [[player alloc]init];
return YES;
}
をして、私は私のviewcontrollersでそれを呼ばれ、
player myPlayer = ((AppDelegate *)[UIApplication sharedApplication].delegate).theMainPlayer;
、私のデリゲートでそれを作成しようとしましたが、これはしませんでした作業。 私は何をやったのか、あるいはプレイヤーオブジェクトを作成してすべてのビューコントローラーで共有するために、他にやりたいことをする方法があれば誰にでも教えてもらえますか?
ありがとうございました
あなたは完全に私の人生を救った!あなたは私がこれに費やした時間は分かりません。ありがとうございました! – Mona