无法使用MediaCapture从音频设备录制mp3文件 [英] Cannot using MediaCapture to record a mp3 file from the audio device

查看:107
本文介绍了无法使用MediaCapture从音频设备录制mp3文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我想问你的专业
经验 
解决我的问题。我正在尝试使用音频设备(麦克风)和MediaCapture类录制mp3文件。


我找到了一些链接和
资源 
它是如何工作的,类似于  http://msdn.microsoft.com/en-us/library/windows/apps/hh452798.aspx 和  http://code.msdn.microsoft.com/windowsapps/Media-Capture-Sample-adf87622/


很遗憾  它对我不起作用。结果媒体文件(audioCapture.mp3或audioCapture.m4a)已经创建但它总是空的。


我也试图对MediaCapture使用一些不同的设置,这里只是一个例子:

 captureInitSettings = null; 
captureInitSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
captureInitSettings.audioDeviceId ="" ;;       
captureInitSettings.videoDeviceId ="" ;;
captureInitSettings.streamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.audio;
captureInitSettings.photoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.videoPreview;
captureInitSettings.realTimeModeEnabled = true;
if(deviceList.length> 0)
captureInitSettings.audioDeviceId = deviceList [0] .id;

但在此之后,以下代码只是创建一个空文件:

 Windows.Storage.KnownFolders.musicLibrary.createFileAsync(" audioCapture.mp3",Windows .Storage.CreationCollisionOption.generateUniqueName).done(function(newFile){
storageFile = newFile;
oMediaCapture.startRecordToStorageFileAsync(profile,storageFile).done(function(file){
// some代码在这里
},函数(错误){
WinJS.log&& WinJS.log(错误,"样本","错误");
});
});

我还创建了一个分配给单独按钮的附加功能来停止录制:

 oMediaCapture.stopRecordAsync()。done(function(result){
record State = false;

//播放录制的视频。
var audio = id(" capturedAudio");
audio.src = URL.createObjectURL(storageFile,{oneTimeOnly:true});
audio.play();
id(" message")。innerHTML =" Record Stopped。档案" + storageFile.path +"英寸;
localSettings.values [audioKey] = storageFile.path;

},
errorHandler);


它不起作用!

创建的文件为空通常。


你能帮我或告诉我这里有什么问题吗?


ps:以下相机(照片)捕获示例工作正常 -   http://code.msdn.microsoft.com/windowsapps/CameraCaptureUI-Sample -845a53ac


提前致谢!


Dmitry




< br $>


$


$

解决方案

您好,


关于您的代码,在开始记录时,您正在致电:


MediaCapture.startRecordToStorageFileAsync


停止记录时,您正在调用:


oMediaCapture.stopRecordAsync


所以看起来MediaCapture和oMediaCapture是两个不同的对象。 需要它在开始和结束方法中使用相同的对象。



最好的问候,


Ming Xu。


Hello guys,

I would to ask your professional experience to solve my issue. I'm trying to record a mp3 file using the audio device (microphone) and MediaCapture class.

I have found a few link and resources how it works, something like http://msdn.microsoft.com/en-us/library/windows/apps/hh452798.aspx and http://code.msdn.microsoft.com/windowsapps/Media-Capture-Sample-adf87622/

Unfortunately it doesn't work for me. As a result the media file (audioCapture.mp3 or audioCapture.m4a) has been created but it is always empty.

I also was trying to use some different settings to MediaCapture, here is just one example:

captureInitSettings = null;
captureInitSettings = new Windows.Media.Capture.MediaCaptureInitializationSettings();
captureInitSettings.audioDeviceId = "";        
captureInitSettings.videoDeviceId = "";
captureInitSettings.streamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.audio;
captureInitSettings.photoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.videoPreview;
captureInitSettings.realTimeModeEnabled = true;
if (deviceList.length > 0)
    captureInitSettings.audioDeviceId = deviceList[0].id;

But after that the following code just creating an empty file:

Windows.Storage.KnownFolders.musicLibrary.createFileAsync("audioCapture.mp3", Windows.Storage.CreationCollisionOption.generateUniqueName).done(function (newFile) {
            storageFile = newFile;
       oMediaCapture.startRecordToStorageFileAsync(profile, storageFile).done(function (file) {
                // some code here
            }, function (err) {
                WinJS.log && WinJS.log(err, "sample", "error");
            });
        });

I also have created one additional function assigned to the separate button to stop recording:

oMediaCapture.stopRecordAsync().done(function (result) {
            recordState = false;

            // Playback the recorded video.
            var audio = id("capturedAudio");
            audio.src = URL.createObjectURL(storageFile, { oneTimeOnly: true });
            audio.play();
            id("message").innerHTML = "Record Stopped.  File " + storageFile.path + "  ";
            localSettings.values[audioKey] = storageFile.path;

        },
        errorHandler);

It doesn't work!

Created file is empty as usual.

Could you please help me or tell me what is wrong here?

p.s.: the following Camera (Photo) Capture example works fine - http://code.msdn.microsoft.com/windowsapps/CameraCaptureUI-Sample-845a53ac

Thanks in advance!

Dmitry

解决方案

Hi,

Regard to your code, when starting the record, you’re calling:

MediaCapture.startRecordToStorageFileAsync

When stopping the record, you’re calling:

oMediaCapture.stopRecordAsync

So it looks like MediaCapture and oMediaCapture are two different objects. It is needed to use the same object in both start and stop methods.

Best Regards,

Ming Xu.


这篇关于无法使用MediaCapture从音频设备录制mp3文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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