国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

iOS實現mp3播放效果

2019-10-21 18:46:06
字體:
來源:轉載
供稿:網友

一、工程圖

iOS,mp3,播放

二、代碼

RootViewController.h

#import <UIKit/UIKit.h>//加入AVFoundation.framework頭文件#import <AVFoundation/AVFoundation.h>@interface RootViewController : UIViewController<AVAudioPlayerDelegate>{  //播放器player  AVAudioPlayer *avAudioPlayer;}@end

RootViewController.m

#import "RootViewController.h"//導入AVFoundation.framework#import <AVFoundation/AVFoundation.h>@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];    }

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到IOS開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 普陀区| 榆社县| 元朗区| 岳池县| 时尚| 安阳市| 马鞍山市| 隆德县| 孙吴县| 日照市| 东乡| 永丰县| 靖远县| 思南县| 彝良县| 六枝特区| 西乡县| 合山市| 九龙坡区| 旬邑县| 双鸭山市| 裕民县| 东阳市| 宝鸡市| 黄山市| 柞水县| 沧州市| 磐石市| 龙海市| 微山县| 赣州市| 梁山县| 龙江县| 泰州市| 龙口市| 安塞县| 稻城县| 西乌| 中西区| 巴林右旗| 四子王旗|