• 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];

                }

  • 相关阅读:
    web前端之jQuery
    java之awt编程
    java连接数据库的基本操作
    实习生应聘经历2018/3/1
    javaweb学习之建立简单网站
    mysql之视图
    71. Simplify Path
    347. Top K Frequent Elements
    7. Reverse Integer
    26. Remove Duplicates from Sorted Array
  • 原文地址:https://www.cnblogs.com/guligei/p/3531071.html
Copyright © 2020-2023  润新知