PhoneGap的媒体录制MP3文件已经损坏 [英] Phonegap Media record mp3 file corrupt
问题描述
我使用PhoneGap的媒体录制音频为MP3。录制完成后,小青在我的Android精品和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格式的Android设备上的记录和需要使用的.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.
- 安装封装MediaToolkit - > http://www.nuget.org/packages/MediaToolkit/
-
写这个code:
- Install-Package MediaToolkit --> http://www.nuget.org/packages/MediaToolkit/
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屋!