• reloaddata,btn,info,play,timer,


    #pragma mark - 播放原wav

    - (IBAction)playWav:(id)sender {

        

     

            UIButton *btn = (UIButton *)sender;

            ChatMessageInfo *info = [self.dataArray objectAtIndex:btn.tag];

            NSString *fileName = info.localPath;

            self.soundBtn = btn;

    //    当本地没有的时候,去下载

            if (fileName.length == 0) {

                [self downloadVoice:info];

            }

        

            if (fileName.length > 0)

            {

                if (![fileName isEqualToString:tempFileName])

                {

                    if (currentPlayer) {

                        if ([currentPlayer isPlaying]) {

                            [currentPlayer stop];

                            [currentPlayer setCurrentTime:0.0];

                            

                        }

     

                    }

                    

                    self.player = [self.player initWithContentsOfURL:[NSURL URLWithString:fileName] error:nil];

                    self.player.delegate = self;

                    currentPlayer = self.player;

                }

                tempFileName = fileName;

     

                if ([self.player isPlaying])

                {

                    [self.player stop];

                    [self.player setCurrentTime:0.0];

                    playIndex = -1;

                    [soundTimer setFireDate:[NSDate distantFuture]];

     

                    

     

                }else

                {

                    [self.player play];

                    info.isPlay = YES;

                    playIndex = btn.tag;

     

                }

           }

        [selfupdateVoicePlayState];

     

    }

     

     

    -(void)updateVoicePlayState

    {

        for (int i = 0; i< self.dataArray.count; i++) {

            ChatMessageInfo *info = [self.dataArray objectAtIndex:i];

            if (i == playIndex) {

                info.isPlay = YES;

            }else{

                info.isPlay = NO;

            }

        }

        [self.tableViewreloadData];

    }

     

    -(void)updateMeter

    {

        if (!soundTimer) {

     

    //        soundTimer = [NSTimer scheduledTimerWithTimeInterval:0.2f target:self selector:@selector(updateSound) userInfo:Nil repeats:YES];

            soundTimer = [NSTimertimerWithTimeInterval:0.2ftarget:selfselector:@selector(updateSound) userInfo:Nilrepeats:YES];

            [[NSRunLoopcurrentRunLoop] addTimer:soundTimerforMode:NSRunLoopCommonModes];

     

        }

        [soundTimersetFireDate:[NSDatedistantPast]];

     

        

    }

     

     

    -(void)updateSound

    {

       NSIndexPath *_path = [NSIndexPathindexPathForItem:playIndexinSection:0];

       IMVoiceCell *cell = (IMVoiceCell *)[self.tableViewcellForRowAtIndexPath:_path];

        self.soundBtn = cell.soundBtn;

        

        TTLog(@".......................%d",self.soundBtn.tag);

        switch (soundCount)

        {

            case 0:

            {

                [self.soundBtnsetImage:[UIImageimageNamed:@"celebrity_chatto_voice_playing_f1.png"] forState:UIControlStateNormal];

                break;

     

            }

                case 1:

            {

                [self.soundBtnsetImage:[UIImageimageNamed:@"celebrity_chatto_voice_playing_f2.png"] forState:UIControlStateNormal];

                break;

            }

            default:

            {

                [self.soundBtnsetImage:[UIImageimageNamed:@"celebrity_chatto_voice_playing_f3.png"] forState:UIControlStateNormal];

                break;

     

            }

           

        }

        soundCount ++;

        if (soundCount > 3) {

            soundCount = 0;

        }

    }

     if (!info.isPlay) {

                    [voiceCell.soundBtnsetImage:[UIImageimageNamed:@"celebrity_chatto_voice_playing.png"] forState:UIControlStateNormal];

                }else{

                    [self updateMeter];

                }

  • 相关阅读:
    Markdown
    DNS解析流程
    maven 的各种命令
    ES6初体验——(1)let和const命令
    table相关的选择器 & children()与find()的区别 & 选择器eq(n)与nth-child(n)的差异
    Java MD5加密类
    POI操作Excel异常Cannot get a text value from a numeric cell
    MyEclipse+SSH开发环境配置
    JdbcTemplate详解
    Spring配置声明
  • 原文地址:https://www.cnblogs.com/guligei/p/3531071.html
Copyright © 2020-2023  润新知