ios - AVAudioPlayer无法播放MP3文件

标签 ios audio avaudioplayer audiotoolbox

我有两个MP3文件。我可以播放第一个文件,但不能播放iOS上的第二个文件。

我正在使用AVAudioPlayer播放它们。

我能够播放的第一个文件具有以下信息。

0000000 49 44 33 03 00 00 00 00 21 76 54 49 54 32 00 00
0000010 00 11 00 00 00 4e 68 6f 74 65 20 4d 61 20 53 65
0000020 74 20 4e 61 65 4d 43 44 49 00 00 00 aa 00 00 45


played.mp3: Audio file with ID3 version 2.3.0, contains: MPEG ADTS, layer III, 
v1, 128 kbps, 44.1 kHz, JntStereo

无法播放的剪辑具有以下信息。
0000000 49 44 33 04 00 00 00 00 00 5b 54 50 45 31 00 00
0000010 00 0a 00 00 03 43 6f 6c 64 70 6c 61 79 00 54 49
0000020 54 32 00 00 00 08 00 00 03 59 65 6c 6c 6f 77 00

yellow.mp3: Audio file with ID3 version 2.4.0, contains: MPEG ADTS, layer III,  
v2.5,  24 kbps, 8 kHz, Monaural

我拉头发是因为我可以使用VLC或iTunes在Mac上很好地播放它们。但是,我的iOS播放器无法处理第二个剪辑。

第二个怎么了?

这是我可以玩的。 https://www.dropbox.com/s/l93b4f4n63oihf0/cut.mp3?dl=0

这是我不能玩的。 https://www.dropbox.com/s/0xrpyxwzqhb7dzf/yellow.mp3?dl=0

谢谢。

最佳答案

它对我来说很好。检查下面的代码

objective-c

#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>

@interface ViewController ()
{
    AVAudioPlayer *_audioPlayer;
}
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Construct URL to sound file
    NSString *path = [NSString stringWithFormat:@"%@/yellow.mp3", [[NSBundle mainBundle] resourcePath]];
    NSURL *soundUrl = [NSURL fileURLWithPath:path];

    // Create audio player object and initialize with URL to sound
    _audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
    [_audioPlayer play];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end

swift
import UIKit
import AVFoundation

class ViewController: UIViewController {
    var audioPlayer = AVAudioPlayer()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let audioPath = NSBundle.mainBundle().pathForResource("yellow", ofType: "mp3")
        do {
            audioPlayer = try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath!))
            audioPlayer .play()
        }
        catch {
            print("Something bad happened. Try catching specific errors to narrow things down")
        }

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

关于ios - AVAudioPlayer无法播放MP3文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34303922/

相关文章:

audio - 转换采样率时减少/消除 SoX 中的削波

audio - AVCONV : Select german stream not highest quality one

objective-c - 当 AudioSessionActive 为 NO 时,无法通过硬件按钮控制 AVAudioPlayer 的音量

iphone - 如何在单点触控中无间隙地循环播放 mp3?

iphone - REST 套件 0.10.0 - POST 不工作

objective-c - 我想使用 -> 运算符设置 ivar

android - 在桌面上查看移动网站

python - 如何在Python中同时录制音频和视频?

ios - 在两种方法中调用时,在控制中心中快速更新媒体元数据不起作用

ios - 为 uibutton ios 使用 TableView 披露指示器样式