iOS第二天注意和学习重点
2015-07-17 21:49
471 查看
// // QYViewController.m // QYMusicPlayer // // Created by zhangsf on 14-5-17. // Copyright (c) 2014年 zhangsf. All rights reserved. // #import "QYViewController.h" #import <AVFoundation/AVFoundation.h> #import "QYSongsManager.h" #import "QYSong.h" @interface QYViewController () @property (weak, nonatomic) IBOutlet UISlider *sliderMusicTracker; @property (weak, nonatomic) IBOutlet UIButton *btnPreMusic; @property (weak, nonatomic) IBOutlet UIButton *btnPlayMusic; @property (weak, nonatomic) IBOutlet UIButton *btnNextMusic; @property (weak, nonatomic) IBOutlet UILabel *labelCurrentTime; @property (weak, nonatomic) IBOutlet UILabel *labelDuration; @property (weak, nonatomic) IBOutlet UISlider *sliderMusicVolume; @property (weak, nonatomic) IBOutlet UITableView *songWordTableView; @property (strong, nonatomic) NSMutableArray *arraySongName; @property (strong, nonatomic) NSDictionary *dicSongTimeAndLyric; @property (strong, nonatomic) NSMutableArray *arrayLyric; @property (strong, nonatomic) NSArray *currentSongTimes; @property (assign, nonatomic) NSUInteger currentLineNumber; @property (strong, nonatomic) QYSong *currentSong; //计时器, 主要用于控制播放歌典的进度 @property (strong, nonatomic) NSTimer *timerForPlayer; //标识当前播放歌曲在歌曲列表的位置,主要用于下一首,上一首 @property (nonatomic, assign) NSUInteger currentSongIndex; @end //-(void)viewDidload //{super viewDidload //self.currentSongIndex =0; //self.currentLineNumber =0; //[self.songWordTableView registerClass:[UITableViewCell class] forcellresuseidentifer:@"QYMusicCell"] //NSString *path=[[NSBundle mainBundle] resourcepath] // // // @implementation QYViewController - (void)viewDidLoad { [super viewDidLoad]; self.currentSongIndex = 0;//初始化,默认使用第一首歌 self.currentLineNumber = 0; [self.songWordTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"QYMusicCell"]; NSString *path = [[NSBundle mainBundle] resourcePath]; [[QYSongsManager sharedQYSongManager] parserSongInfoWithPath:path]; [self resetMusicPlayer]; //初始化音乐进度Slider [self.sliderMusicTracker setThumbImage:[UIImage imageNamed:@"sliderThumb_small"] forState:UIControlStateNormal]; [self.sliderMusicTracker setThumbImage:[UIImage imageNamed:@"sliderThumb_small"] forState:UIControlStateHighlighted]; // 实始化声音控制Slider [self.sliderMusicVolume setThumbImage:[UIImage imageNamed:@"sliderThumb_small"] forState:UIControlStateNormal]; [self.sliderMusicVolume setThumbImage:[UIImage imageNamed:@"sliderThumb_small"] forState:UIControlStateHighlighted]; self.sliderMusicVolume.value = 0.3f; } #pragma mark - #pragma mark UITableView Data source - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.arrayLyric.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"QYMusicCell"]; cell.textLabel.font = [UIFont boldSystemFontOfSize:13.0f]; cell.textLabel.text = self.arrayLyric[indexPath.row]; return cell; } #pragma mark - #pragma mark Button callback - (IBAction)onPlayerVolume:(UISlider*)sender { self.musicPlayer.volume = sender.value; } - (IBAction)onSliderMusicTracker:(UISlider*)sender { self.musicPlayer.currentTime = sender.value * self.musicPlayer.duration; [self.timerForPlayer invalidate]; self.timerForPlayer = [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(onTimer:) userInfo:nil repeats:YES]; } - (IBAction)onPreMusic:(id)sender { self.currentLineNumber = 0; if ((self.currentSongIndex == 0)) { self.currentSongIndex = [QYSongsManager sharedQYSongManager].arraySongList.count-1; }else { self.currentSongIndex--; } [self resetMusicPlayer]; [self playCurrentSong]; [self.songWordTableView reloadData]; [self updateLyricView]; } - (IBAction)onNextMusic:(id)sender { self.currentLineNumber = 0; self.currentSongIndex++; if (self.currentSongIndex > [QYSongsManager sharedQYSongManager].arraySongList.count-1) { self.currentSongIndex = 0; } [self resetMusicPlayer]; [self playCurrentSong]; [self.songWordTableView reloadData]; [self updateLyricView]; } - (void)resetMusicPlayer { self.currentSong = [[[QYSongsManager sharedQYSongManager] arraySongList] objectAtIndex:self.currentSongIndex]; self.currentSongTimes = [[self.currentSong.dicTimeAndLyric allKeys] sortedArrayUsingSelector:@selector(compare:)]; self.arrayLyric = [NSMutableArray arrayWithCapacity:20]; for (int i = 0 ; i < self.currentSongTimes.count; i++) { NSString *lyric = self.currentSong.dicTimeAndLyric[self.currentSongTimes[i]]; [self.arrayLyric addObject:lyric]; } NSURL *currentMusicURL = [[NSBundle mainBundle] URLForResource:self.currentSong.name withExtension:@"mp3"]; NSError *error = nil; self.musicPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:currentMusicURL error:&error]; if (error != nil) { NSLog(@"INIT music player failure.ERROR:%@",error); return; } // self.sliderMusicTracker.minimumValue = 0.0f; // self.sliderMusicTracker.maximumValue = self.musicPlayer.duration; } - (IBAction)onPlay:(UIButton*)sender { [self playCurrentSong]; } - (void)playCurrentSong { if (![self.musicPlayer isPlaying]) { [self.musicPlayer play]; self.timerForPlayer = [NSTimer scheduledTimerWithTimeInterval:0.1f target:self selector:@selector(onTimer:) userInfo:nil repeats:YES]; [self.btnPlayMusic setBackgroundImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal]; } else { [self.musicPlayer pause]; [self.timerForPlayer invalidate]; [self.btnPlayMusic setBackgroundImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal]; } } - (void)onTimer:(NSTimer*)timer { //动态更新进度条时间 if ((int)self.musicPlayer.currentTime % 60 < 10) { self.labelCurrentTime.text = [NSString stringWithFormat:@"%d:0%d",(int)self.musicPlayer.currentTime / 60, (int)self.musicPlayer.currentTime % 60]; } else { self.labelCurrentTime.text = [NSString stringWithFormat:@"%d:%d",(int)self.musicPlayer.currentTime / 60, (int)self.musicPlayer.currentTime % 60]; } // if ((int)self.musicPlayer.duration % 60 < 10) { self.labelDuration.text = [NSString stringWithFormat:@"%d:0%d",(int)self.musicPlayer.duration / 60, (int)self.musicPlayer.duration % 60]; } else { self.labelDuration.text = [NSString stringWithFormat:@"%d:%d",(int)self.musicPlayer.duration / 60, (int)self.musicPlayer.duration % 60]; } NSLog(@"%f,%f",self.musicPlayer.currentTime,self.musicPlayer.duration); double result = self.musicPlayer.currentTime / self.musicPlayer.duration; NSLog(@"result %f",result); [self.sliderMusicTracker setValue:result animated:YES]; [self updateLyricView]; } - (void)updateLyricView { //如果是最后一行歌词, 需要处理的办法 if (self.currentLineNumber >= self.currentSongTimes.count ) { self.currentLineNumber= 0; [self.timerForPlayer invalidate]; [self.musicPlayer stop]; } else //如果不是最后一行, 则进行的处理 { double lyricTime = [self.currentSongTimes[self.currentLineNumber] doubleValue]; NSLog(@"lyricTime is %f,currentTime:%f",lyricTime,self.musicPlayer.currentTime); if (self.musicPlayer.currentTime - lyricTime > 0) { // 浮点数比较,注意事项 self.currentLineNumber++; } } NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.currentLineNumber-1 inSection:0]; [self.songWordTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
vim编辑器的功能及用法:剪切文档和粘贴文档,盲打指法,和简单的hello word
vi m编辑器,设置页码set number 复制文字,起始页,结束行 w 文件名;合并:文件名 r
objective-c代码不能用gcc +文件名进行编译,c 程序语言可以用gcc +文件名 ./a.out进行运行。原因是,oc语言是进行加强的语言,不能进行编译,初学者,被推荐看
objective-c基础语言教程,自我觉得学iOS应该是从大方向掌握其主要概貌,应该是从基础和高处同时学习,打算了解objective-c library的类数量,并且了解一下c语言,今天了解了@interface和@ implement的简单介绍,为什么有的函数有返回值,有的没有尚未查到,此为目前想了解的音乐播放器
相关文章推荐
- iOS动画中的物理知识应用之愤怒的小鸟-重力加速度
- iOS开发中获取上月的起止时间(NSCalendar、NSDateComponents和NSDate的使用)
- 小白学开发(iOS)基础C_指针(2015-07-17)
- iOS应用程序开发过程的简述
- iOS9编程GOGOGO:XCode7新变化
- iOS端使用二维码扫描(ZBarSDK)和生成(libqrencode)功能
- iOS--阅读--优秀博客
- iOS--效率
- iOS开源框架及项目大全(一定有你想要的,后期在不断进行分类方便大家查阅)
- iOS--动画--转场动画
- ios 开发关键字IBInspectable
- ios学习笔记--(c基础题3)
- iOS笔记058 - IOS之多线程
- 招聘一个靠谱的 iOS
- iOS开发--常用Mac终端命令
- iOS 实现类似微博或者陌陌上的显示附近位置信息功能。
- ios 串
- IOS - 用户信息界面
- iOS 获取当前屏幕显示的viewcontroller
- 个人常用iOS第三方库以及XCode插件介绍