(国内知名安卓开发论坛推荐:http://www.eoeandroid.com/)
此代码是IOS一款播放器代码,学习时自己仿照主流播放器写的,该播放器支持各种格式播放,支持上一曲,下一曲,歌词同步播放,音量调节大小,快进,快退等功能,后续功能我会继续完善。代码仅供学习交流,如有写的不好,望各位海涵...希望对刚刚接触这块的童鞋有所帮助......
001 #import “ZJViewController.h”
002 #import “ZjMusic.h”
003
004
005 @interface ZJViewController ()<AVAudioPlayerDelegate,UITabBarDelegate,UITableViewDataSource>
006
007 @end
008 #define kBtnHeight 50
009 #define kBtnWidth 60
010 @implementation ZJViewController
011
012 - (void)viewDidLoad
013 {
014 [super viewDidLoad];
015 [self initView];
016 [self initData];
017
018
019
020 // NSLog(@“%@”,self.lrcDict);
021 }
022 -(void)initData
023 {
024 ZjMusic *music1 = [[ZjMusic alloc] initWithName:@“Right Here Waiting(此情可待)” andType:@“mp3”];
025 ZjMusic *music2 = [[ZjMusic alloc] initWithName:@“Beyond-真的爱你” andType:@“mp3”];
026 ZjMusic *music3 = [[ZjMusic alloc] initWithName:@“刘德华-爱你一万年” andType:@“mp3”];
027 ZjMusic *music4 = [[ZjMusic alloc] initWithName:@“毛宁-涛声依旧” andType:@“mp3”];
028 ZjMusic *music5 = [[ZjMusic alloc] initWithName:@“你是我的眼” andType:@“mp3”];
029 ZjMusic *music6 = [[ZjMusic alloc] initWithName:@“星星” andType:@“mp3”];
030 ZjMusic *music7 = [[ZjMusic alloc] initWithName:@“月光爱人” andType:@“mp3”];
031
032
033 self.musicData = [[NSMutableArray alloc] init];
034
035 [self.musicData addObject:music1];
036 [self.musicData addObject:music2];
037 [self.musicData addObject:music3];
038 [self.musicData addObject:music4];
039 [self.musicData addObject:music5];
040 [self.musicData addObject:music6];
041 [self.musicData addObject:music7];
042 [self loadMusic:music5];
043 [self initLrc:music5];
044
045 self.musicNameLabel.text = music5.name;
046
047
048
049 }
050 #pragma mark 加载Music
051 -(void)loadMusic:(ZjMusic*)music
052 {
053 NSString *path = [[NSBundle mainBundle] pathForResource:music.name ofType:music.type];
054 NSURL *URL = [NSURL fileURLWithPath:path];
055
056 self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:URL error:nil];
057 self.audioPlayer.delegate = self;
058 self.audioPlayer.volume = 0.5;
059 self.volumeSlider.value = self.audioPlayer.volume;
060 [self.audioPlayer prepareToPlay];
061
062 [self returnTotalTime];
063
064 }