日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

objective-c 多媒体 音乐播放

發(fā)布時間:2025/3/21 72 豆豆
生活随笔 收集整理的這篇文章主要介紹了 objective-c 多媒体 音乐播放 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>

//

//? ViewController.m

//? 音樂播放

//

//? Created by DC017 on 15/12/28.

//? Copyright ? 2015 DC017. All rights reserved.

//


#import "ViewController.h"

//引入音樂播放器框架

#import <AVFoundation/AVFoundation.h>

@interface ViewController ()<AVAudioPlayerDelegate>

@property(nonatomic,strong)AVAudioPlayer *audioPlayer;

@end

@implementation ViewController

- (void)viewDidLoad {

? ? [super viewDidLoad];

? ? [self.audioPlayer play];

? ? _audioPlayer.delegate=self;

? ??

}

//get方法

-(AVAudioPlayer *)audioPlayer{

? ? NSLog(@"get 方法被調(diào)用");

? ? if (!_audioPlayer) {

? ? ? ? NSLog(@"播放器準(zhǔn)備啟動,開始實(shí)例化");

? ? ? ? //1獲取音樂文件路徑 注意:這里獲取的時相對路經(jīng)

? ? ? ? NSString * strurl=[[NSBundle mainBundle] pathForResource:@"逍遙嘆" ofType:@"mp3"];

? ? ? ? NSURL * url=[NSURL fileURLWithPath:strurl];

? ? ? ? //初始化音樂播放器

? ? ? ? NSError * error;

? ? ? ? _audioPlayer=[[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error];

? ? ? ? //設(shè)置播放屬性

? ? ? ? _audioPlayer.numberOfLoops=0;//0表示為不循環(huán),負(fù)數(shù)表示為無線循環(huán)

? ? ? ? //獲取總秒數(shù)duration

? ? ? ? NSLog(@"總秒數(shù)%f",_audioPlayer.duration);

?? ? ? ? [_audioPlayer prepareToPlay];//加載音頻到緩存? ? ? ?

? ? }

? ? return _audioPlayer;

}

-(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{

? ? NSLog(@"音樂播放完成");

}

- (void)didReceiveMemoryWarning {

? ? [super didReceiveMemoryWarning];

? ? // Dispose of any resources that can be recreated.

}


@end


轉(zhuǎn)載于:https://my.oschina.net/u/2483781/blog/552953

總結(jié)

以上是生活随笔為你收集整理的objective-c 多媒体 音乐播放的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。