xcode 中用AvAudioPlayer播放mp3文件

       [playButton setEnabled:YES];

        NSError *playerError;

        AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[[[NSURL alloc] initFileURLWithPath:mp3FilePath] autorelease] error:&playerError];

        self.player = audioPlayer;

        player.volume = 1.0f;

        if (player == nil)

        {

            NSLog(@"ERror creating player: %@", [playerError description]);

        }

        [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategorySoloAmbient error: nil];

        player.delegate = self;

 

 

- (void)playPause

{

    //If the track is playing, pause and achange playButton text to "Play"

    if([player isPlaying])

    {

        [player pause];

        [playButton setTitle:@"Play" forState:UIControlStateNormal];

    }

    //If the track is not player, play the track and change the play button to "Pause"

    else

    {

        [player play];

        [playButton setTitle:@"Pause" forState:UIControlStateNormal];

    }

}

 

       

posted @ 2014-08-13 13:01  LAOS  阅读(584)  评论(0编辑  收藏  举报