单击按钮不播放音频

时间:2014-01-24 12:19:26

标签: ios button audio ibaction

在以下代码中没有错误,但仍然没有播放音频 我做错了什么?

-(IBAction)buttonPressed:(id)sender
{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"ABC"
                                                   message: @" ABC"
                                                  delegate: self
                                         cancelButtonTitle:@"Cancel"
                                         otherButtonTitles:@"OK",nil];

    [alert show];

    AVAudioPlayer *audioplayer;
    NSString *audiopath = [[NSBundle mainBundle] pathForResource:@ "1Abhi Kuch Dino Se.mp3" ofType:@ "mp3"];
    NSURL *audioURL = [NSURL fileURLWithPath:audiopath];
    audioplayer = [[AVAudioPlayer alloc]initWithContentsOfURL:audioURL error:nil];
    [audioplayer play];
} 

1 个答案:

答案 0 :(得分:1)

试试这个。从路径资源中删除.mp3

NSString *audiopath =[[NSBundle mainBundle] pathForResource:@ "1Abhi Kuch Dino Se" ofType:@ "mp3"];