簡體   English   中英

單擊按鈕時無聲音

[英]No sound when button clicked

當我單擊按鈕時,我嘗試播放聲音,聲音剪輯為10秒,應用程序運行良好,當我單擊按鈕時,什么也沒有發生,沒有錯誤或什么都沒有,這是我的代碼

.m file
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
- (IBAction)Play:(id)sender {

    AVAudioPlayer *audioPlayer;
    NSString *audioPath = [[NSBundle mainBundle]pathForResource:@"Blesgaes" ofType:@"mp3"];
    NSURL *audioURL =[NSURL fileURLWithPath:audioPath];
    audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioURL error:nil];
    [audioPlayer play];
}
.h file
#import <AVFoundation/AVFoundation.h>


@interface ViewController : UIViewController
- (IBAction)Play:(id)sender;

我添加了AVFoundation框架,並且按照以下步驟操作

http://looksok.wordpress.com/2013/01/19/ios-tutorial-play-sound/ http://www.techotopia.com/index.php/Playing_Audio_on_an_iPhone_using_AVAudioPlayer_(iOS_6)http:// code-and- coffee.blogspot.in/2012/09/how-to-play-audio-in-ios.html

任何想法我在做什么錯。

下面是簡單的代碼:

  - (IBAction)playAudio:(id)sender {
   AVAudioPlayer *audioPlayer;
   NSString *audioPath = [[NSBundle 
    mainBundle] pathForResource:@"Woof" 
    ofType:@"mp3"];
  NSURL *audioURL = [NSURL 
  fileURLWithPath:audioPath];
NSError *audioError = [[NSError alloc] init];
audioPlayer = [[AVAudioPlayer alloc]    
 initWithContentsOfURL:audioURL 
 error:&audioError];

   if (!audioError) {
    [audioPlayer play];
    NSLog(@"Woof!");
}
else {
    NSLog(@"Error!");
}
   }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM