2011-08-28 7 views
0

10 개의 이미지 파일과 사운드 파일이 있고 "a.png"를 표시하면 "a.mp3"을 재생하려고합니다. 그런 다음 "다음"버튼을 클릭하면 "b.png"가 표시되고 "b.mp3"가 재생됩니다. 이 문제를 어떻게 해결할 수 있습니까?하나씩 표시된 이미지로 사운드 재생

답변

0

소리를 재생하려면이 .h 파일에 다음을 입력하십시오. AVAudioPlayer * theaudio;

NSString * path = [[NSBundle mainBundle] pathForResource : @ "nameofmusicfile"ofType : @ "mp3"];이 파일은 음악을 재생할 때 .m에 저장됩니다. theaudio = [[AVAudioPlayer alloc] initWithContentsOfURL : [NSURL fileURLWithPath : path] 오류 : NULL]; [경로 해제]; [theaudio play]; 중지하려면 [theaudio stop]을 사용하십시오.

이미지 표시 UIImageView * i;

i = [[UIImageView alloc] initWithImage : [UIImage imageNamed : @ "image.png"]]];

[view addSubview : i]; 이동하려면 i.center = CGPointMake (0.0,0.0);

+0

답변을 주셔서 감사합니다.하지만 그것이 하나의 작업 그룹이라고 생각합니다. – ersin

1
-(void) viewDidLoad;{ 


sounds = [[NSArray alloc]initWithObjects:@"a.mp3", @"b.mp3",@"c.mp3", nil]; 


imageArray = [[NSArray arrayWithObjects: 
       [UIImage imageNamed:@"a.jpg"], 
       [UIImage imageNamed:@"b.jpg"], 
       [UIImage imageNamed:@"c.jpg"], 
       nil] retain]; 
[super viewDidLoad];} 
-(IBAction) next; { 
currentSound++; 
if (currentSound >= sounds.count) currentSound = 0; 
//what kind of code play this sound////images work perpectly but sound not// 


currentImage++; 
if (currentImage >= imageArray.count) currentImage = 0; 
UIImage *img = [imageArray objectAtIndex:currentImage]; 
[imageView setImage:img];}