PhoneGap的媒体录制MP3文件已经损坏 [英] Phonegap Media record mp3 file corrupt

查看:170
本文介绍了PhoneGap的媒体录制MP3文件已经损坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PhoneGap的媒体录制音频为MP3。录制完成后,小青在我的Andr​​oid精品和Windows媒体播放器正常播放。然而,当我尝试在浏览器中它说,该文件已损坏。

I am using phonegap media to record audio as mp3. After recording, it plays fine on my Android and plays fine on Windows Media Player. However, when I try it in the browser it says that the file is corrupt.

完全错误的:

铬:我们现在不能播放音频文件。

Chrome: "We cannot play this audio file right now."

火狐:视频不能播放,因为文件已损坏

Firefox: "Video can't be played because the file is corrupt."

IE浏览器:打开WMP中的文件,它起着

IE: Opens the file in WMP and it plays.

我使用的例子中,code。的http://docs.phonegap.com/en/2.6.0/cordova_media_media.md.html#media.startRecord

I used the code from the example. http://docs.phonegap.com/en/2.6.0/cordova_media_media.md.html#media.startRecord

// Record audio
// 
function recordAudio() {
    var src = "myrecording.mp3";
    var mediaRec = new Media(src,
        // success callback
        function() {
            console.log("recordAudio():Audio Success");
        },

        // error callback
        function(err) {
            console.log("recordAudio():Audio Error: "+ err.code);
        });

    // Record audio
    mediaRec.startRecord();
}

先谢谢了。

编辑:

下面是一个例子。 http://blrbrdev.azurewebsites.net/voice/blrbr_130419951008830874.mp3
这起到WMP而不是浏览器。

Here is an example. http://blrbrdev.azurewebsites.net/voice/blrbr_130419951008830874.mp3 This plays in WMP but not the browser.

推荐答案

首先感谢@ Forestan06指着我在正确的方向。

Firstly thanks to @Forestan06 for pointing me in the right direction.

对于那些你为.amr格式的Andr​​oid设备上的记录和需要使用的.Net C#您的服务器上的mp3格式所说的记录,这是我如何做的。

For those of you recording on Android devices in .amr format and needing said recording in .mp3 format on your server using .Net C#, this is how I did it.


  1. 安装封装MediaToolkit - > http://www.nuget.org/packages/MediaToolkit/

  2. 写这个code:

  1. Install-Package MediaToolkit --> http://www.nuget.org/packages/MediaToolkit/
  2. Write this code:

var fileName ="myVoice.mp3";
string fileNameWithPath = Server.MapPath("~/Voice/" + fileName);

if (request.FileName.EndsWith(".amr"))
{
    var amrFileName = "myVoice.amr";
    string amrFileNameWithPath = Server.MapPath("~/Voice/Amr/" + amrFileName);
    request.SaveAs(amrFileNameWithPath);

    var inputFile = new MediaFile { Filename = amrFileNameWithPath };
    var outputFile = new MediaFile { Filename = fileNameWithPath };

    using (var engine = new Engine())
    {
        engine.Convert(inputFile, outputFile);
    }

}
else
{
    request.SaveAs(fileNameWithPath);
}


这篇关于PhoneGap的媒体录制MP3文件已经损坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆