1
A
답변
8
하우투에서에서 : http://wiki.monotouch.net/HowTo/Sound/Play_a_Sound_or_Alert
var sound = SystemSound.FromFile (new NSUrl ("File.caf"));
sound.PlaySystemSound();
3
모노에 대해서는 잘 모르지만 iPhone SDK에서는 사운드를 쉽게 만들고 재생하는 것이 쉽지 않습니다. 다른 대안으로는 사운드를 파일로 제공하여 재생하거나 사인 곡선을 나타내는 배열을 만들어 오디오 래퍼에 넣고 여러 사운드 API 중 하나로 전달하는 것입니다.
모노가 제한적일 뿐이라면, System Sound Services 및 AVAudioPlayer의 stackoverflow.com을 시작점으로 검색하십시오.
는 여기에 사운드 파일을 재생하는 방법은 두 가지입니다 : (애플 기준)
SoundEffect.c을
#import "SoundEffect.h"
@implementation SoundEffect
+ (id)soundEffectWithContentsOfFile:(NSString *)aPath {
if (aPath) {
return [[[SoundEffect alloc] initWithContentsOfFile:aPath] autorelease];
}
return nil;
}
- (id)initWithContentsOfFile:(NSString *)path {
self = [super init];
if (self != nil) {
NSURL *aFileURL = [NSURL fileURLWithPath:path isDirectory:NO];
if (aFileURL != nil) {
SystemSoundID aSoundID;
OSStatus error = AudioServicesCreateSystemSoundID((CFURLRef)aFileURL, &aSoundID);
if (error == kAudioServicesNoError) { // success
_soundID = aSoundID;
} else {
NSLog(@"Error %d loading sound at path: %@", error, path);
[self release], self = nil;
}
} else {
NSLog(@"NSURL is nil for path: %@", path);
[self release], self = nil;
}
}
return self;
}
-(void)dealloc {
AudioServicesDisposeSystemSoundID(_soundID);
NSLog(@"Releasing in SoundEffect");
[super dealloc];
// self = nil;
}
-(void)play {
AudioServicesPlaySystemSound(_soundID);
}
-(void)playvibe {
AudioServicesPlayAlertSound(_soundID);
}
+(void)justvibe {
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
}
@end
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
사용 방법 :
// load the sound
gameOverSound = [[SoundEffect alloc] initWithContentsOfFile:[mainBundle pathForResource:@"buzz" ofType:@"caf"]];
// play the sound
[gameOverSound playvibe];
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 갈 때 모든 엑스트라를 볼 수 있습니다) :
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];
+1
어떻게 사운드 파일을 재생하나요? –
관련 문제
- 1. WinForms에서 소리를 재생하려면 어떻게해야합니까?
- 2. C를 사용하여 Linux에서 소리를 재생하려면 어떻게해야합니까?
- 3. 목록보기 항목을 클릭 할 때 소리를 재생하려면 어떻게해야합니까?
- 4. Silverlight에서 간단한 사운드를 재생하려면 어떻게해야합니까?
- 5. 배열을 사용하여 버튼을 특정 순서로 재생하려면 어떻게해야합니까?
- 6. (최상의) WP7에서 반복적으로 사운드를 재생하려면 어떻게해야합니까?
- 7. andengine에서 mp3를 재생하려면 어떻게해야합니까?
- 8. iframe에서 URL을 재생하려면 어떻게해야합니까?
- 9. 안드로이드에서 내 벨소리를 재생하려면 어떻게해야합니까?
- 10. 리소스에서 비디오 파일을 재생하려면 어떻게해야합니까?
- 11. swfloader에서 YouTube 비디오를 재생하려면 어떻게해야합니까?
- 12. Haxe에서 FLV 파일을 재생하려면 어떻게해야합니까?
- 13. iPhone에서 키 누르기 소리를 녹음하는 방법은 무엇입니까?
- 14. MonoTouch를 사용하여 plist 파일 읽기
- 15. 내 iPhone 프로그램이 m4p 미디어를 재생하려면 어떻게해야합니까?
- 16. 서버에서 보낸 웨이브 파일을 재생하려면 어떻게해야합니까?
- 17. Silverlight 3에서 wav 파일을 재생하려면 어떻게해야합니까?
- 18. jquery 및 mootools를 멋지게 재생하려면 어떻게해야합니까?
- 19. C#의 메모리 스트림에서 MP3를 재생하려면 어떻게해야합니까?
- 20. cdg 파일 (노래방)을로드하고 재생하려면 어떻게해야합니까?
- 21. iPhone SDK에서 여러 사운드를 한꺼번에 재생하려면 어떻게해야합니까?
- 22. iPad에서 MPMoviePlayerViewController를 통해 동영상을 재생하려면 어떻게해야합니까?
- 23. 단추를 눌러 사용자 지정 사운드를 재생하려면 어떻게해야합니까?
- 24. Alvas.Audio를 사용하여 소리를 감지하는 방법?
- 25. MonoTouch를 사용한 인앱 광고?
- 26. OpenTK/MonoTouch를 사용하여 정점 목록에서 그리기?
- 27. Monotouch를 사용하여 .net DataServices에 연결 하시겠습니까?
- 28. VB.NET을 사용하여 MonoTouch를 개발할 수 있습니까?
- 29. GData를 사용하여 iPhone에서 Google 사용자를 인증하려면 어떻게해야합니까?
- 30. iPhone에서 동시에 마이크에서 소리를 녹음하고 녹음 할 수 있습니까?
이 방법을 사용할 수 있으며 여전히 휴대 전화의 볼륨 설정을 따르십니까? 필자의 경우 iPod touch의 음량은 줄었지만 sound.PlaySystemSound()는 최대 음량으로 재생됩니다. – Ender2050