【问题标题】:Get mp3 file frolm tableView select从表视图选择中获取 mp3 文件
【发布时间】:2012-02-24 06:48:24
【问题描述】:

我试图从 tableView 行中提取一个 mp3 文件,当用户单击 tableViewCell 时,我希望该 mp3 文件在 detailView 上播放。但是代码有问题。这是我在 DetailViewController 上的代码:

当我选择行时,我得到一个线程 1:程序接收信号:NSString *file 行的“SIGABRT”。谢谢

- (void)viewDidLoad {

    textLabel.text = lullabyLabelString;
    NSString *fileName = lullabyMP3String;


    NSString *file = [[NSBundle mainBundle] pathForResource:[NSURL fileURLWithPath:fileName] ofType:NULL];


    NSError *error = nil;
    AVAudioPlayer *theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:file]error:&error];
    theAudio.delegate = self;
    [theAudio prepareToPlay];
    [theAudio play];

    [super viewDidLoad];
}

【问题讨论】:

    标签: ios uitableview nsdictionary avaudioplayer


    【解决方案1】:

    NSBundlepathForResource: ofType: 需要一个 NSString 而不是 NSURL。

    尝试将该行更改为:

    NSString *file = [[NSBundle mainBundle] pathForResource:fileName ofType:nil];
    

    由于您没有说明,我认为您的文件实际上没有任何文件扩展名。如果是这样,请确保您在上面的那一行中提供了一个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-12
      • 2014-02-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多