私は最初のカスタムクラス "AudioPlayer"を作成しようとしました。私はテーブルビューから "AudioPlayer"にデータ(オーディオタイトル)を渡し、initWithContentsOfURL:[NSURL fileURLWithPath:path]でAudioPlayerをロードしたいのですが、私の "MainViewController"に "AudioPlayer" "互換性のないポインタ型は、 'Audio Player * ___ strong'とAVAudioPLayer *型の式を初期化します。私の質問は、どのように私はカスタムオーディオプレーヤーをURLとして選択したオーディオのタイトルで初期化するのですか? AVAudioPlayerの変数を作成したときはうまく動作しますが、カスタムクラスに渡す方法はわかりません。ここでカスタムNSObjectにデータを渡しますか?
は...ここ
#import "AudioPlayer.h"
@implementation AudioPlayer
@synthesize audioPlayer;
-(void)playPause{
if ([audioPlayer isPlaying]) {
[audioPlayer pause];
} else {
[audioPlayer play];
}
}
-(void)volumeSlider
{
//Setup the volume slider
volumeTimer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(updateVolumeSlider) userInfo:nil repeats:YES];
[audioPlayer setVolume:volumeSlider.value];
}
@end
がMAINVIEW実装です...ここで
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>
@interface AudioPlayer : NSObject{
AVAudioPlayer *audioPlayer;
//Volume slider
NSTimer *volumeTimer;
IBOutlet UISlider *volumeSlider;
}
-(bool) isPlaying;
-(bool) isPaused;
-(void)playPause:(id)sender;
@property (nonatomic, retain) AVAudioPlayer *audioPlayer;
@end
は私のカスタムクラスの実装ファイル..です私のカスタムクラスのヘッダである
- (void)viewDidLoad
{
[super viewDidLoad];
//Instantiate performanceArray
performanceArray = [[NSMutableArray alloc]initWithObjects:@"Centering", nil];
//Instantiate recoveryArray
recoveryArray = [[NSMutableArray alloc]initWithObjects:@"Power Nap", nil];
//Instantiate the AudioPlayer
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:self.tableView.indexPathForSelectedRow];
NSString *path = [[NSBundle mainBundle] pathForResource:cell.textLabel.text ofType:@"m4a"];
AudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
[audioPlayer.audioPlayer prepareToPlay];
}
ありがとうございます。あなたは私にURLを渡す簡単な例を教えてください。 – arynhard
ありがとうございます。 – arynhard
** NSURL * theURL = [NSURL fileURLWithPath:path]エラー:NULL]; **でセレクタのインスタンスメソッドがわからないエラーが発生しました**インスタンスメッセージのReceiver type 'AudioPlayer'はメソッドを宣言していませんセレクタ 'initWitURL:' on ** AudioPlayer * audioPlayer = [[AudioPlayer alloc] initWitURL:theURL]; ** – arynhard