2012-01-03 6 views
0

pickerViewコントローラを使用して複数のサウンドアプリケーションを持つ1つのミュージックプレーヤーがありますが、アプリケーションをビルドしようとするとサウンドが出力されません。誰でも私のコードのトラブルシューティングを手伝うことができますか?ここでトラブルシューティングのための私のコードです。iOS:サウンドファイルがPickerViewControllerで再生できない

.Hファイル

#import <UIKit/UIKit.h> 
#import <AVFoundation/AVFoundation.h> 


@interface ViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource, AVAudioPlayerDelegate> { 

    UIPickerView  *picker; 
    UILabel   *musicTitle; 
    NSMutableArray  *musicList; 
    AVAudioPlayer  *audioPlayer; 


} 


@property (nonatomic, retain) IBOutlet UIPickerView *picker; 
@property (nonatomic, retain) IBOutlet UILabel *musicTitle; 
@property (nonatomic, retain) NSMutableArray *musicList; 

-(IBAction)playSelectedMusic:(id)sender; 


@end 

.mファイル

 - (void)viewDidLoad 
     { 
      [super viewDidLoad]; 

      musicList = [[NSMutableArray alloc] initWithObjects:@"music1",@"music2",@"music3",@"music4",@"music5", 
         @"music6",nil]; 
     } 

    -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row 
      inComponent:(NSInteger)component 
    { 



     if ([[musicList objectAtIndex:row] isEqual:@"music1"]) 
     { 


      NSURL *path = [[NSBundle mainBundle] URLForResource:@"music1" withExtension:@"mp3"]; 
      AVAudioPlayer *theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:path error:NULL]; 


      theAudio.delegate = self; 
      [theAudio play]; 

      NSString *resultString = [[NSString alloc] initWithFormat: 
             @"music1", 
             [musicList objectAtIndex:row]]; 
      musicTitle.text = resultString; 


     } 

-(IBAction)playSelectedMusic:(id)sender{ 

    how do i call the didSelectRow & put it here ? 

} 

答えて

0
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row 
     inComponent:(NSInteger)component 

pickerview.delegate =自己を設定してみてください。

は、pickerviewのデリゲートを設定すると自動的に呼び出されます。明示的に> playSelectedの音楽ボタンは必要ありません。

+0

私はpickerview.delegate = selfを設定しようとします。ビルド時にこのエラーが発生します。関数ポインタを見つけることができませんCreateAudio – Amink

+0

私はpickerview.delegate = selfを設定しようとしています。ビルド時にこのエラーが発生します。私のコンソールには次のように書いてあります:CFBundle/CFPlugInのファクトリCreateAudioを見つけることができません(バンドル、ロードされていません) – Amink

+0

pls親切にこのリンクを参照してくださいhttps ://discussions.apple.com/thread/2220669?start = 0&tstart = 0 – raghul

関連する問題