国产探花免费观看_亚洲丰满少妇自慰呻吟_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開發頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 沙坪坝区| 留坝县| 碌曲县| 阿荣旗| 盐亭县| 宜城市| 宝应县| 昌平区| 永川市| 苍南县| 故城县| 鹤山市| 海城市| 东安县| 闵行区| 大新县| 灵石县| 高安市| 颍上县| 太湖县| 芜湖县| 克东县| 滦南县| 天等县| 南和县| 泰来县| 桂阳县| 顺平县| 北宁市| 和田市| 鄂伦春自治旗| 宜阳县| 龙州县| 高唐县| 马龙县| 金塔县| 北碚区| 印江| 中牟县| 板桥市| 西丰县|