1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Documents;
  8. using System.Windows.Input;
  9. using System.Windows.Media;
  10. using System.Windows.Media.Animation;
  11. using System.Windows.Shapes;
  12. using Microsoft.Phone.Controls;
  13. using Microsoft.Xna.Framework.Audio;
  14. using System.IO;

  15. using System.Windows.Threading;
  16. using Microsoft.Xna.Framework;


  17. namespace PhoneApp1
  18. {
  19.     public partial class MainPage : PhoneApplicationPage
  20.     {
  21.          Microphone microphone = Microphone.Default;
  22.          byte[] microphoneBuffer;
  23.          MemoryStream audioStream;
  24.          byte[] recording;
  25.         // 构造函数
  26.         public MainPage()
  27.         {
  28.             InitializeComponent();
  29.         }
  30.         //开始
  31.         private void button1_Click(object sender, RoutedEventArgs e)
  32.         {
  33.             audioStream = new MemoryStream();
  34.             microphone.BufferDuration = TimeSpan.FromMilliseconds(1000);
  35.             microphoneBuffer = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)];
  36.             microphone.BufferReady += microphoneBuffer_BufferReady;
  37.             microphone.Start();
  38.         }
  39.         //结束
  40.         private void button2_Click(object sender, RoutedEventArgs e)
  41.         {
  42.             microphone.Stop();
  43.             microphone.BufferReady -= microphoneBuffer_BufferReady;
  44.             audioStream.Flush();
  45.             recording = audioStream.ToArray();
  46.             audioStream.Dispose();
  47.            
  48.         }
  49.         //播放
  50.         private void button3_Click(object sender, RoutedEventArgs e)
  51.         {
  52.             var effect = new SoundEffect(recording, microphone.SampleRate, AudioChannels.Mono);
  53.             effect.Play();
  54.         }
  55.         void microphoneBuffer_BufferReady(object sender, EventArgs e)
  56.         {
  57.             microphone.GetData(microphoneBuffer);
  58.             audioStream.Write(microphoneBuffer, 0, microphoneBuffer.Length);
  59.         }
  60.     }
  61. }
复制代码
报错说

错误

错误
多年以后你会不会记得我在2V2的时候那么深情的骂你是傻逼,我的兄弟!
高级构架师 2# Jaly1991 发表于 2012-2-22 19:48:26
图片有点小啊
QQ截图20120222194215.png
多年以后你会不会记得我在2V2的时候那么深情的骂你是傻逼,我的兄弟!
高级构架师 3# Jaly1991 发表于 2012-2-22 19:56:31
解决了

点评

详情 回复 Vincent  发表于 2012-2-22 21:50:36

how?
多年以后你会不会记得我在2V2的时候那么深情的骂你是傻逼,我的兄弟!
首席构架师 4# zsj20082008 发表于 2012-2-22 21:49:58
楼主解决了就分享下吧

点评

详情 回复 Jaly1991  发表于 2012-2-23 10:02:07

Re: 看6#
孜孜不倦!天道酬勤!
管理员 5# Vincent 发表于 2012-2-22 21:50:36
Jaly1991 发表于 2012-2-22 19:56
解决了

how?

点评

详情 回复 Jaly1991  发表于 2012-2-23 10:01:16

1、在Silverlight应用程序中使用XNA Game Studio,需要模拟Game循环来使我们的程序能够正常的实施。 2、定义下面的App.class XNAAsyncDispatcher类并将它添加到App()构造函数的下一行。定义类XNAAsyncDispatcher这样
高筑墙,广积粮!
高级构架师 6# Jaly1991 发表于 2012-2-23 10:01:16
Vincent 发表于 2012-2-22 21:50
how?

1、在Silverlight应用程序中使用XNA Game Studio,需要模拟Game循环来使我们的程序能够正常的实施。
2、定义下面的App.class XNAAsyncDispatcher类并将它添加到App()构造函数的下一行。
  1. ApplicationLifetimeObjects.Add(new XNAAsyncDispatcher(TimeSpan.FromMilliseconds(50)));
复制代码
定义类XNAAsyncDispatcher
  1. public class XNAAsyncDispatcher : IApplicationService
  2.     {
  3.         private DispatcherTimer _frameworkDispatcherTimer;
  4.         public XNAAsyncDispatcher(System.TimeSpan dispatchInterval)
  5.         {
  6.             FrameworkDispatcher.Update();
  7.             this._frameworkDispatcherTimer = new DispatcherTimer();
  8.             this._frameworkDispatcherTimer.Tick += new EventHandler(frameworkDispatcherTimer_Tick);
  9.             this._frameworkDispatcherTimer.Interval = dispatchInterval;
  10.         }
  11.         void IApplicationService.StartService(ApplicationServiceContext context)
  12.         {
  13.             this._frameworkDispatcherTimer.Start();
  14.         }
  15.         void IApplicationService.StopService()
  16.         {
  17.             this._frameworkDispatcherTimer.Stop();
  18.         }
  19.         void frameworkDispatcherTimer_Tick(object sender, EventArgs e)
  20.         {
  21.             FrameworkDispatcher.Update();
  22.         }
  23.     }
复制代码
这样就OK了。
多年以后你会不会记得我在2V2的时候那么深情的骂你是傻逼,我的兄弟!
高级构架师 7# Jaly1991 发表于 2012-2-23 10:02:07
zsj20082008 发表于 2012-2-22 21:49
楼主解决了就分享下吧

Re:
看6#
多年以后你会不会记得我在2V2的时候那么深情的骂你是傻逼,我的兄弟!
您需要登录后才可以回帖 登录 | 注册

关于我们|手机版|Archiver|DEVDIV.COM ( 京ICP备07040843号 )  

GMT+8, 2012-5-19 17:12

Powered by DEVDIV.COM!

© 2010-2012 DEVDIV.COM Coummunity.

回顶部