首页 > 其他 > 详细

reloaddata,btn,info,play,timer,

时间:2014-01-23 20:56:41      阅读:493      评论:0      收藏:0      [点我收藏+]

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

            }

reloaddata,btn,info,play,timer,

原文:http://www.cnblogs.com/guligei/p/3531071.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!