听书简单应用
来源:互联网 发布:淘宝游戏专营还会开吗 编辑:程序博客网 时间:2024/05/17 04:45
#import "XJViewController.h"
#import "XJWord.h"
#import "MJExtension.h"
#import "XJAduioTool.h"
@interface XJViewController ()
@property (nonatomic, strong) NSArray *words;
@property (nonatomic, strong) CADisplayLink *link;
@property (nonatomic, strong) AVAudioPlayer *audioPlayer;
@end
@implementation XJViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// 播放背景音乐
[XJAduioTool playMusicWithMusicName:@"Background.caf"];
// 播放朗诵音乐
self.audioPlayer = [XJAduioTool playMusicWithMusicName:@"一东.mp3"];
// 开启定时器
[self.link addToRunLoop:[NSRunLoop mainRunLoop ] forMode:NSDefaultRunLoopMode];
}
#pragma mark - tableView的代理
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.words.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 1.创建cell
static NSString *ID = @"word";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
}
// 2.设置cell的数据
XJWord *word = self.words[indexPath.row];
cell.textLabel.text = word.text;
return cell;
}
#pragma mark - 懒加载
-(NSArray *)words
{
if (!_words) {
self.words = [XJWord objectArrayWithFilename:@"一东.plist"];
}
return _words;
}
- (CADisplayLink *)link
{
if (_link == nil) {
_link = [CADisplayLink displayLinkWithTarget:self selector:@selector(updata)];
}
return _link;
}
- (void)updata
{
double currentime = self.audioPlayer.currentTime;
// 遍历取出上下两行的时间段,然后跟当前的时间进行比较,然后tableview就选择那一行
for (int i = 0; i < self.words.count; i ++) {
//当前词句
XJWord *cureetWord = self.words[i];
// 下一条词句
int next = i;
if (next < self.words.count - 1) {
next ++;
}
XJWord *nextWord = self.words[next];
if (currentime >= cureetWord.time && currentime <= nextWord.time) {
// 主动选择下一行
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
[self.tableView selectRowAtIndexPath:indexPath animated:0 scrollPosition:UITableViewScrollPositionNone];
}
}
}
- 听书简单应用
- 点酷听书手机客户端应用源码
- 2011听书之目录
- iphone 的听书软件
- 很嗨听书客户端
- 得到听书笔记
- 教你搜狐听书任意下
- 【无限互联】学员作品:懒人听书
- 且听且读 听书软件
- “叶语清音”&卓意听书
- 卓意听书の樊登读书会
- 卓意听书の樊登读书会
- 听书-中国人为什么看不起中国人-张鸣
- 得到内容分析 专栏 每天听书
- 读书与听书:我的2007年度非工作盘点
- 小米平板 粉色版 16GB,不可以听书
- iOS 语音播放文字内容--制作简易听书软件(AVSpeechSynthesizer)
- 听书与看书,看电视有何区别优势?
- 学java教程之构造方法重载
- openwrt新手编译注意部分
- 用init创建的的控制器的视图会从下加载
- hdu 2066 一个人的旅行(Dijkstra求最短路)
- android Rect的使用
- 听书简单应用
- 自定义PopupWindow
- QT5.3.1和VS2013链接出错
- Android中的Rect与RectF
- 音乐播放器项目中要注意的
- Google开源实时通信项目WebRTC
- 用url读取沙河路径,或要写入的方法
- 欧拉定理、费马小定理、逆元理论基础
- eclipse集成svn后出现Failed to load JavaHL Library的解决办法