歌词加载学习笔记

ios收获:ios中break语句的作用是跳过本层的for循环,而continue只是停止执行这一次循环,从而跳出这一次循环。就是继续执行之后的循环罢了。

 

1、首先从本地解析歌词文件。Lrc歌词文件时间来确定定时播放的数据。

 

 

通过

NSString *LRCPath = [[NSBundle mainBundle] pathForResource:[musicArray[musicArrayNumber] name] ofType:@"lrc"];
    NSString *contentStr = [NSString stringWithContentsOfFile:LRCPath encoding:NSUTF8StringEncoding error:nil];
    NSArray *array = [contentStr componentsSeparatedByString:@"\n"];

来解析数据,首先把所有的歌词文件加载到一个string中,然后通过通过相关的解码,来获得真实的数据,

array使用"/n"换行。从而得到一行数据,将所有的数据加载到一个数组中。

通过for循环遍历所有的数据,从而获得每一个数据来做相关的处理,根据歌词中的"]"字符串来分割相关的数据。

从而将时间和数据分开。然后再将时间根据":"和"."来分割开来,载入先关的数据。time和lrcstr。。。

 

 

- (NSString *)substringWithRange:(NSRange)aRange
可以从不规则的字符串中取出自己需要的字符,并且可以通过组装来实现例如时间的解集

 通过这个格式来截取不规则格式的音频的时间。

通过定时器来定时加载歌词,其中通过歌词的长度来判读需要执行的歌词跳转,

//动态显示歌词
-(void)displayLrc:(NSUInteger )timer
{

    for (int i =0 ; i<[timeArray count]; i++) {
        NSArray * array = [timeArray[i] componentsSeparatedByString:@":"];
        NSUInteger currentTime = [array[0] intValue]*60 +[array[1] intValue];
     
        if(i == ([timeArray count]-1))
        {
            NSArray *array1 = [timeArray[timeArray.count-1] componentsSeparatedByString:@":"];
            NSUInteger currentTime1 = [array1[0] intValue]*60 +[array1[1] intValue];
            if (timer>currentTime1) {
            [self updataLRC:i];
                            }
            break;
#warning  这里有一个问题
           
        }else
        {
            //求出第一句的时间点,在第一句显示前的时间内一直加载第一句
            NSArray *array2 = [timeArray[0] componentsSeparatedByString:@":"];
            NSUInteger currentTime2 = [array2[0] intValue] * 60 + [array2[1] intValue];
            if (timer < currentTime2) {

                [self updataLRC:0];
                //                NSLog(@"马上到第一句");
               break;
            }
        NSArray *array3 = [timeArray[i+1] componentsSeparatedByString:@":"];
         NSUInteger currentTime3 = [array3[0] intValue]*60 +[array3[1] intValue];
        if (timer >=currentTime && timer<=currentTime3) {
            [self updataLRC:i];
     break;
        }
    }
    }
}
//更新选中的代码。
-(void)updataLRC:(NSUInteger)lineNumber { lrcLineNum = lineNumber; [centerTableView reloadData]; NSIndexPath *indexPath= [NSIndexPath indexPathForRow:lineNumber inSection:0 ]; NSLog(@"indexPath %@",indexPath); [centerTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; }

在tableview的datasorce方法中加载判断需要跳转的界面

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    if (tags == 0) {
        
        return [timeArray count];
    }
    else if (tags ==1)
    {
        return [timeArray count];
    }
    
    return [timeArray count];
}

tags是绑定的全部变量,来判断点击事件触发的时候加载的是哪一个segment。

从而来返回相关的tableview cell的个数。

在tableview的datasorce方法 来实现动态加载歌词。

 1 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
 2 {
 3     static NSString* cellIndentify = @"LRCCell";
 4     UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIndentify];
 5     if (cell ==nil) {
 6         cell  = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentify];
 7     }
 8     if (indexPath.row == lrcLineNum) {
 9 //        cell.textLabel.text = lrcDict[timeArray[indexPath]];
10         cell.textLabel.text = lrcDict[timeArray[indexPath.row]];
11         cell.textLabel.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1.0];
12         cell.textLabel.font = [UIFont systemFontOfSize:15];
13     }else
14     {
15         cell.textLabel.text = lrcDict[timeArray[indexPath.row]];
16         cell.textLabel.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
17         cell.textLabel.font = [UIFont systemFontOfSize:13];
18     }
19     cell.backgroundColor = [UIColor clearColor];
20     return cell;
21 }

第一次写这么长的代码。好高兴。哈哈

转载于:https://www.cnblogs.com/asheng/p/4372964.html

内容概要:本文系统介绍了算术优化算法(AOA)的基本原理、核心思想及Python实现方法,并通过图像分割的实际案例展示了其应用价值。AOA是一种基于种群的元启发式算法,其核心思想来源于四则运算,利用乘除运算进行全局勘探,加减运算进行局部开发,通过数学优化器加速函数(MOA)和数学优化概率(MOP)动态控制搜索过程,在全局探索与局部开发之间实现平衡。文章详细解析了算法的初始化、勘探与开发阶段的更新策略,并提供了完整的Python代码实现,结合Rastrigin函数进行测试验证。进一步地,以Flask框架搭建前后端分离系统,将AOA应用于图像分割任务,展示了其在实际工程中的可行性与高效性。最后,通过收敛速度、寻优精度等指标评估算法性能,并提出自适应参数调整、模型优化和并行计算等改进策略。; 适合人群:具备一定Python编程基础和优化算法基础知识的高校学生、科研人员及工程技术人员,尤其适合从事人工智能、图像处理、智能优化等领域的从业者;; 使用场景及目标:①理解元启发式算法的设计思想与实现机制;②掌握AOA在函数优化、图像分割等实际问题中的建模与求解方法;③学习如何将优化算法集成到Web系统中实现工程化应用;④为算法性能评估与改进提供实践参考; 阅读建议:建议读者结合代码逐行调试,深入理解算法流程中MOA与MOP的作用机制,尝试在不同测试函数上运行算法以观察性能差异,并可进一步扩展图像分割模块,引入更复杂的预处理或后处理技术以提升分割效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值