我有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