码迷,mamicode.com
首页 > 其他好文 > 详细

xcode 中用AvAudioPlayer播放mp3文件

时间:2014-08-13 14:31:26      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:des   os   io   文件   for   ar   amp   log   

       [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];

    }

}

 

       

xcode 中用AvAudioPlayer播放mp3文件,布布扣,bubuko.com

xcode 中用AvAudioPlayer播放mp3文件

标签:des   os   io   文件   for   ar   amp   log   

原文地址:http://www.cnblogs.com/HuiLove/p/3909852.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!