• 播放wav的方法,


    #pragma mark - 播放原wav

    - (IBAction)playWav:(id)sender {

        

     

            UIButton *btn = (UIButton *)sender;

            playIndex = btn.tag;

            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)

            {

    //            对于同一个音频文件的重复点击,不再进行生成新的player

                if (![fileName isEqualToString:tempFileName])

                {

                    

    //                暂停播放的player,开一个新的player

                    if (self.player) {

                        if ([self.player isPlaying]) {

                            [self.player stop];

                            [self.player setCurrentTime:0.0];

                            [selfupdateVoicePlayStateSwitch:kStophasBeforeIndex:YES];

                        }

     

                    }

                    self.player = [[AVAudioPlayeralloc] initWithContentsOfURL:[NSURLURLWithString:fileName] error:Nil];

                    self.player.delegate = self;

                }

                tempFileName = fileName;

     

                if ([self.player isPlaying])

                {

                    [self.player stop];

                    [self.player setCurrentTime:0.0];

                    [selfupdateVoicePlayStateSwitch:kStophasBeforeIndex:NO];

     

                }else

                {

                    [self.player play];

                    [selfupdateVoicePlayStateSwitch:kStarthasBeforeIndex:NO];

     

                }

           }

        beforeIndex = btn.tag;

     

     

    }

     

     

    -(void)updateVoicePlayStateSwitch:(int)_type hasBeforeIndex:(BOOL)_hasIndex

    {

        NSIndexPath *mIndexPath;

        if (_hasIndex) {

            ChatMessageInfo *info = [self.dataArrayobjectAtIndex:beforeIndex];

            info.isPlay = _type;

            _type == 1?[self startTimer]:[self stopTimer];

           mIndexPath = [NSIndexPath indexPathForRow:beforeIndex inSection:0];

        }else{

            ChatMessageInfo *info = [self.dataArrayobjectAtIndex:playIndex];

            info.isPlay = _type;

            _type == 1?[self startTimer]:[self stopTimer];

           mIndexPath = [NSIndexPath indexPathForRow:playIndex inSection:0];

        }

        

        NSArray *indexArray = [NSArray arrayWithObject:mIndexPath];

       [self.tableViewreloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationNone];

    }

  • 相关阅读:
    gRPC java 客户端,服务器端通讯使用json格式
    HDTV(1920x1080)码率和视频质量关系的研究 2 (实验结果)
    Fedora 18/19没有注销
    window API一天一练之邮槽
    在C语言环境下使用google protobuf
    Cantor展开式
    LeetCode题解:Rotate List
    不知不觉vs2012 update 4出来了
    http://download.csdn.net/detail/yanzi1225627/6548337
    【虚拟化实战】Cluster设计之一资源池
  • 原文地址:https://www.cnblogs.com/guligei/p/3531501.html
Copyright © 2020-2023  润新知