有没有人有通过iPhone上的midi> wav转换等播放.midi文件的经验?

时间:2009-07-07 10:06:08

标签: iphone midi

有没有人有通过iPhone上的midi> wav转换等播放.midi文件的经验?

1 个答案:

答案 0 :(得分:0)

Iphone需要声音采用某些有效格式。不确定是否直接支持midi,但MacOSX附带了一个命令行工具来转换声音。

我会在声音文件上运行以下命令,将它们转换为我知道的格式。

afconvert -v -f caff -d ima4 -c 1 filename.ext

播放声音效果或环境声音,如下所示

+ (void)PlaySFX:(NSString*)name
{
    NSUserDefaults* savedState = [NSUserDefaults standardUserDefaults]; 

    if ([savedState boolForKey:SFX])
    {
        UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
        AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (sessionCategory), &sessionCategory); 

        SystemSoundID sound;  
        AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:name ofType:@"caf"]], &sound);  
        AudioServicesPlaySystemSound (sound);   
    }
}

+ (void)StartAmbientSound
{
    NSUserDefaults* savedState = [NSUserDefaults standardUserDefaults]; 

    player = [[AVAudioPlayer alloc] initWithContentsOfURL: [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Volcano Erupting" ofType:@"caf"]] error: nil];
    player.numberOfLoops = -1;
    player.currentTime = 0;
    player.volume = [savedState floatForKey:MUSICVOL];
    [player play];  
}