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

    }

  • 相关阅读:
    [转] 英语飙升的好方法
    jndi数据源方式配制SPY
    OJB查询
    ODP.NET应用之我所见
    C#中利用ODP实现瞬间导入百万级数据详解
    Sys.Extended.UI' is null or not an object 中文的訊息
    oracle数据库连接字符串
    seo
    宽幅FLASH产品展示代码多图带左右显示按钮 图
    网站盈利模式分类详解
  • 原文地址:https://www.cnblogs.com/guligei/p/3531501.html
Copyright © 2011-2022 走看看