zoukankan      html  css  js  c++  java
  • 播放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];

    }

  • 相关阅读:
    Linux VPS新硬盘分区与挂载教程
    全程图解 手把手教您开启windows终端服务
    解决IE apk变成zip:Android 手机应用程序文件下载服务器Nginx+Tomcat配置解决方法
    Nginx 配置文件详解
    MySQL新建用户,授权,删除用户,修改密码
    解决IE apk变成zip:Android 手机应用程序文件下载服务器 配置解决方法
    CentOS 6.4 32位系统 LAMP(Apache+MySQL+PHP)安装步骤
    yum被锁Another app is currently holding the yum lock; waiting for it to exit...
    CentOS 6.4下编译安装MySQL 5.6.14
    Oracle函数大全
  • 原文地址:https://www.cnblogs.com/guligei/p/3531501.html
Copyright © 2011-2022 走看看