重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

iOS实现mp3播放效果

一、工程图

鹿寨网站制作公司哪家好,找创新互联!从网页设计、网站建设、微信开发、APP开发、成都响应式网站建设等网站项目制作,到程序开发,运营维护。创新互联从2013年开始到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联

iOS实现mp3播放效果

二、代码

RootViewController.h

#import 
//加入AVFoundation.framework头文件
#import 

@interface RootViewController : UIViewController

{
  //播放器player
  AVAudioPlayer *avAudioPlayer;
}

@end

RootViewController.m

#import "RootViewController.h"

//导入AVFoundation.framework
#import 


@interface RootViewController ()

@end

@implementation RootViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
  self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  if (self) {
    // Custom initialization
  }
  return self;
}

- (void)viewDidLoad
{
  [super viewDidLoad];
  // Do any additional setup after loading the view.
  
  self.title=@"MP3的播放";
}

-(void)initPlay
{
  //从budle路径下读取音频文件
  NSString *string = [[NSBundle mainBundle] pathForResource:@"母亲" ofType:@"mp3"];
  
  //把音频文件转换成url格式
  NSURL *url = [NSURL fileURLWithPath:string];
  
  //初始化音频类 并且添加播放文件
  avAudioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
  
  //开始进行播放
  [avAudioPlayer play];
  
  
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持创新互联。


名称栏目:iOS实现mp3播放效果
新闻来源:http://cqcxhl.com/article/gssjsp.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP