在麦克风中暂停和恢复:Windows phone 7

时间:2013-09-17 07:20:31

标签: asp.net windows-phone-7 windows-phone-8

我是Windows手机的初学者。我创建了录音机示例,并在Windows Phone 7中成功执行。但我必须在我的应用程序中添加暂停和恢复功能。

注意:我使用麦克风录音。

如何在麦克风中设置推送和恢复功能以进行录制?

或者给我任何替代解决方案,以便在Windows手机中录制。

这是我的代码..

Microphone mphone;
List<byte[]> memobuffercollection = new List<byte[]>();
DynamicSoundEffectInstance playback;

private void BtnRecords_Click(object sender, RoutedEventArgs e)
{
   // Clear the collection for storing the buffers
   memobuffercollection.Clear();

   // Stop any playback in Progress
   playback.Stop();

   // Start Recording
   mphone.Start();        
   BtnStop.Opacity = 1;
   BtnRecords.Opacity = 0;        
}    

private void BtnStop_Click(object sender, RoutedEventArgs e)
{
    StopRecording();
    BtnStop.Opacity = 0;
    BtnRecords.Opacity = 1;
}

void StopRecording()
{
    // Get the last partial buffer
    int sampleSize = mphone.GetSampleSizeInBytes(mphone.BufferDuration);
    byte[] extraBuffer = new byte[sampleSize];
    int extraBytes = mphone.GetData(extraBuffer);

    // Stop Recording
    mphone.Stop();                  

    // Create MemoInfo object and add at top of collection
    int totalSize = memobuffercollection.Count * sampleSize + extraBytes;
    TimeSpan duration = mphone.GetSampleDuration(totalSize);
    MemoInfo memoInfo = new MemoInfo(DateTime.UtcNow, totalSize, duration);
    memofiles.Insert(0, memoInfo);

    // Save Data in IsolatedStorage 
    using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
    {
        using (IsolatedStorageFileStream stream = storage.CreateFile(memoInfo.FileName))
        {
            // Write buffers from collection
            foreach (byte[] buffer in memobuffercollection)
                stream.Write(buffer, 0, buffer.Length);

            // Write partial buffer
            stream.Write(extraBuffer, 0, extraBytes);
        }
    }

    memosListBox.UpdateLayout();
    memosListBox.ScrollIntoView(memoInfo);


}

memoinfo是我的课程,用于为录制的音频提供标题。

1 个答案:

答案 0 :(得分:1)

如果您查看Microphone的{​​{3}},就会发现Pause()课程中没有Resume()Microphone方法。只有播放有Pause&amp;恢复功能(阅读documentation)。

暂停和暂停的唯一方法恢复,是“停止录制”,保存音频文件,并在“恢复”时录制新文件。最后,将音频文件合并为一个。

相关问题(虽然适用于Windows Phone 8):this