Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
自定义拨号器iOS的DTMF声音_Ios_Objective C_Avaudioplayer - Fatal编程技术网

自定义拨号器iOS的DTMF声音

自定义拨号器iOS的DTMF声音,ios,objective-c,avaudioplayer,Ios,Objective C,Avaudioplayer,我正在尝试将dtmf声音添加到我的自定义拨号板中。 我设法在触地时为每一个数字复制一个声音。现在,我正在尝试实现当拨号的人对号码进行“长按”时的自然通话行为。 问题是声音结束了。我怎样才能让它持续到触摸结束的时候? 在我现在的代码中,我试图添加一个长的声音,即使我正在使用触地事件,只是为了测试它是否有效。如果是的话,我会为长按添加手势识别器 这是我的密码: @interface ViewController : UIViewController<AVAudioPlayerDelegate&

我正在尝试将dtmf声音添加到我的自定义拨号板中。 我设法在触地时为每一个数字复制一个声音。现在,我正在尝试实现当拨号的人对号码进行“长按”时的自然通话行为。 问题是声音结束了。我怎样才能让它持续到触摸结束的时候? 在我现在的代码中,我试图添加一个长的声音,即使我正在使用触地事件,只是为了测试它是否有效。如果是的话,我会为长按添加手势识别器

这是我的密码:

@interface ViewController : UIViewController<AVAudioPlayerDelegate>{
 //SystemSoundID toneSSIDs[12];
    AVAudioPlayer *toneSSIDs[12];
}
@end

@implementation ViewController

-(id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if(self)
    {
        for(int count = 0; count < 12; count++){
           NSString *toneFilename = [NSString stringWithFormat:@"dtmf-%d", count];

            NSURL *toneURLRef = [[NSBundle mainBundle] URLForResource:toneFilename
                                                        withExtension:@"mp3"];

            player = [[AVAudioPlayer alloc]initWithContentsOfURL:toneURLRef error:NULL ];
            player.volume = 0.4f;

            toneSSIDs[count] = player;
        }
    }

    return self;
}

-(void)playSoundForKey:(int)key {
    _sound = toneSSIDs[key];
    _sound.delegate = self;
    _sound.numberOfLoops = -1;
    [_sound prepareToPlay];
    [_sound play];
}

- (IBAction)touchNum:(id)sender {
  [self playSoundForKey:[sender tag]];
}
@界面ViewController:UIViewController{
//SystemSoundID-toneSSIDs[12];
AVAudioPlayer*toneSSIDs[12];
}
@结束
@实现视图控制器
-(id)initWithCoder:(NSCoder*)aDecoder
{
self=[super initWithCoder:aDecoder];
如果(自我)
{
对于(int count=0;count<12;count++){
NSString*toneFilename=[NSString stringWithFormat:@“dtmf-%d”,计数];
NSURL*toneURLRef=[[NSBundle mainBundle]URLForResource:toneFilename
带分机:@“mp3”];
player=[[AVAudioPlayer alloc]initWithContentsOfURL:toneURLRef错误:NULL];
player.volume=0.4f;
toneSSIDs[count]=玩家;
}
}
回归自我;
}
-(无效)playSoundForKey:(int)键{
_声音=音调符号[键];
_sound.delegate=self;
_sound.numberOfLoops=-1;
[声音准备播放];
[声音播放];
}
-(iAction)touchNum:(id)发送方{
[self-playSoundForKey:[sender-tag]];
}

我试着使用.wav和.mp3两种声音并循环播放,但我得到了多种声音,而不是我需要的长声音。谁来帮忙

尝试将其设置为无限循环,触地时调用
[\u sound play]
,触地时调用
[\u sound stop]
,触地时它只是停止循环,但循环始终相同..多个声音,而不是长的声音:(您能否延长播放的音调的播放长度,然后按照@SimonMcLoughlin的建议执行?例如,如果您当前的音调为:03,则制作一个新的音调,即:30,并在触地/上地时播放/停止该音调。虽然从技术上讲,这无法解决您提出的确切问题,但它可能解决声音中断的问题(除了罕见的长按之外)应该有一种方法以正确的方式循环,避免使用更长的声音。我们无法预测用户按下按钮的时间!