如何使用MonoTouch在iPhone上播放声音?
我在找像这样的东西如何使用MonoTouch在iPhone上播放声音?,iphone,audio,xamarin.ios,Iphone,Audio,Xamarin.ios,我在找像这样的东西 PlaySound (uint frequency) 它存在吗?我不知道mono,但在iphonesdk中,创建和播放声音并不容易。其他方法是将声音作为文件提供并播放,或者创建一个表示正弦波的数组,并将其包装在音频包装器中,然后将其传递给许多声音API中的一个 如果mono被证明同样有限,那么从stackoverflow.com搜索System Sound Services和AVAudioPlayer作为起点 以下是播放声音文件的两种方法: SoundEffect.c(基于
PlaySound (uint frequency)
它存在吗?我不知道mono,但在iphonesdk中,创建和播放声音并不容易。其他方法是将声音作为文件提供并播放,或者创建一个表示正弦波的数组,并将其包装在音频包装器中,然后将其传递给许多声音API中的一个 如果mono被证明同样有限,那么从stackoverflow.com搜索System Sound Services和AVAudioPlayer作为起点 以下是播放声音文件的两种方法: SoundEffect.c(基于苹果的) SoundEffect.h:
#import <AudioToolbox/AudioServices.h>
@interface SoundEffect : NSObject {
SystemSoundID _soundID;
}
+ (id)soundEffectWithContentsOfFile:(NSString *)aPath;
- (id)initWithContentsOfFile:(NSString *)path;
- (void)play;
- (void)playvibe;
+ (void)justvibe;
@end
当您想要以与iPhone的音量控制设置相同的音量播放声音时,这非常有用,并且您不需要停止或暂停声音
另一种方式是:
+ (AVAudioPlayer *) newSoundWithName: (NSString *) name;
{
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource: name ofType: @"caf"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL
error: nil];
[fileURL release];
// if the sound is large and you need to preload it:
[newPlayer prepareToPlay];
return (newPlayer);
}
并使用它(使用AVAudioPlayer时,您可以看到所有附加功能):
我不知道mono,但在iPhone SDK中,创建和播放声音并不是那么容易。其他方法是将声音作为文件提供并播放,或者创建一个表示正弦波的数组,并将其包装在音频包装器中,然后将其传递给许多声音API中的一个 如果mono被证明同样有限,那么从stackoverflow.com搜索System Sound Services和AVAudioPlayer作为起点 以下是播放声音文件的两种方法: SoundEffect.c(基于苹果的) SoundEffect.h:
#import <AudioToolbox/AudioServices.h>
@interface SoundEffect : NSObject {
SystemSoundID _soundID;
}
+ (id)soundEffectWithContentsOfFile:(NSString *)aPath;
- (id)initWithContentsOfFile:(NSString *)path;
- (void)play;
- (void)playvibe;
+ (void)justvibe;
@end
当您想要以与iPhone的音量控制设置相同的音量播放声音时,这非常有用,并且您不需要停止或暂停声音
另一种方式是:
+ (AVAudioPlayer *) newSoundWithName: (NSString *) name;
{
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource: name ofType: @"caf"];
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
AVAudioPlayer *newPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL
error: nil];
[fileURL release];
// if the sound is large and you need to preload it:
[newPlayer prepareToPlay];
return (newPlayer);
}
并使用它(使用AVAudioPlayer时,您可以看到所有附加功能):
从HowTo网站:
从HowTo网站:
您如何播放声音文件?您如何播放声音文件?是否可以使用此方法并仍遵循手机的音量设置?在我的例子中,iPod touch的音量已调低,但声音。PlaySystemSound()以最大音量播放…是否可以使用这种方法并仍然遵循手机的音量设置?在我的例子中,iPod touch的音量已经调低了很多,但是声音。PlaySystemSound()以全音量播放。。。
timePassingSound = [AVAudioPlayer newSoundWithName:@"ClockTicking"];
[timePassingSound play];
// change the volume
[timePassingSound volume:0.5];
// pause to keep it at the same place in the sound
[timePassingSound pause];
// stop to stop completely, and go to beginning
[timePassingSound stop];
// check to see if sound is still playing
[timePassingSound isPlaying];
var sound = SystemSound.FromFile (new NSUrl ("File.caf"));
sound.PlaySystemSound ();