我有10个图像文件和声音文件,当我显示“a.png”时,我想播放“a.mp3”。然后当我点击“下一步”按钮时,显示“b.png”并播放“b.mp3”。我该如何解决这个问题?用显示的图像逐个播放声音
0
A
回答
0
要播放声音,请使用此 在.h文件中输入以下内容: AVAudioPlayer * theaudio;
这个在你的.m文件中,当你想播放音乐时 NSString * path = [[NSBundle mainBundle] pathForResource:@“nameofmusicfile”ofType:@“mp3”]; theaudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]; [路径发布]; [theaudio play]; 停止它,使用[theaudio停止];
显示图像使用UIImageView * i;
i = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@“image.png”]];
把它放在 - [view addSubview:i]; 移动它i.center = CGPointMake(0.0,0.0);
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];}
相关问题
- 1. 使用AVAudioPlayer逐个播放一组声音
- 2. 播放声音
- 3. 播放声音
- 4. 播放声音?
- 5. 逐个显示图像
- 6. 使用系统声音播放声音
- 7. 播放第二个声音
- 8. c中声音播放后的声音#
- 9. 试图播放声音使用AVFoundation
- 10. VC++播放声音
- 11. Ruby声音播放
- 12. MonoTouch:播放声音
- 13. 声音未播放
- 14. 声音未播放
- 15. 如何从声音的开始播放/暂停声音和声音播放?
- 16. 用AKAudioPlayer播放声音 - iOS
- 17. 用javascript播放声音
- 18. 用C++播放声音?
- 19. 用javascript播放声音
- 20. 用Monotouch播放声音
- 21. 用Vue.js播放声音
- 22. 用Python播放声音
- 23. 使用JavaScript播放声音
- 24. 当另一个声音播放时停止播放先前的声音
- 25. Libgdx停止当前正在播放的声音并播放一个新声音
- 26. 使用SoundManager播放多个声音
- 27. 播放声音作为系统声音
- 28. android:播放音频文件并动态显示图像
- 29. 的Python - 播放声音
- 30. Windows Phone的声音播放
感谢您的回答,但我认为这是一组工作... – ersin