简体   繁体   中英

Audio is not playing on click button

In the following code there is no error, but it is still not playing the audio.
What am I doing wrong?

-(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];
} 

Try this. remove .mp3 from Path resource.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM