windows phone 7 通过麦克风录音,并且播放
原文:windows phone 7 通过麦克风录音,并且播放
//模拟XNA的框架(凡是在wp7中应用xna的都必须先模拟此类)
public class XNAAsyncDispatcher : IApplicationService
{
private DispatcherTimer frameworkDispatcherTimer;
public XNAAsyncDispatcher(TimeSpan dispatchInterval)
{
this.frameworkDispatcherTimer = new DispatcherTimer();
this.frameworkDispatcherTimer.Tick += new EventHandler(frameworkDispatcherTimer_Tick);
this.frameworkDispatcherTimer.Interval = dispatchInterval;
}
void IApplicationService.StartService(ApplicationServiceContext context)
{
this.frameworkDispatcherTimer.Start();
}
void IApplicationService.StopService()
{
this.frameworkDispatcherTimer.Stop();
}
void frameworkDispatcherTimer_Tick(object sender, EventArgs e)
{
FrameworkDispatcher.Update();
}
}
在App 构造函数里写
this.ApplicationLifetimeObjects.Add(new XNAAsyncDispatcher(TimeSpan.FromMilliseconds(50))); 当程序激动时就开始模拟XNA GameTimer
//后代代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO;
using Microsoft.Xna.Framework.Audio; namespace Wp7_录音
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
mic.BufferReady += Default_BufferReady;
SoundEffect.MasterVolume = 1.0f;
} MemoryStream ms;
Microphone mic = Microphone.Default; // Wire up an event handler so we can empty the buffer when full
// Crank up the volume to max // When the buffer's ready we need to empty it
// We'll copy to a MemoryStream
// We could push into IsolatedStorage etc
void Default_BufferReady(object sender, EventArgs e)
{
byte[] buffer = new byte[1024];
int bytesRead = 0;
while ((bytesRead = mic.GetData(buffer, 0, buffer.Length)) > 0)
ms.Write(buffer, 0, bytesRead);
}
// The user wants to start recording. If we've already made
// a recording, close that MemoryStream and create a new one.
// Start recording on the default device.
private void start_Click(object sender, RoutedEventArgs e)
{
if (ms != null)
ms.Close();
ms = new MemoryStream();
mic.Start();
}
// The user wants to stop recording. Checks the microphone
// is stopped. Reset the MemoryStream position.
// Play back the recording. Pitch is based on slider value
private void stop_Click(object sender, RoutedEventArgs e)
{
if (mic.State != MicrophoneState.Stopped)
mic.Stop();
ms.Position = 0;
SoundEffect se = new SoundEffect(ms.ToArray(), mic.SampleRate, AudioChannels.Mono);
//se.Play(1.0f, (float)slider1.Value, 0.0f);
se.Play();
}
}
}
本实例UI就两个Button 一个start 一个stop, 还有一个滑动条 Silder.
windows phone 7 通过麦克风录音,并且播放的更多相关文章
- iOS 实时录音和播放
需求:最近公司需要做一个楼宇对讲的功能:门口机(连接WIFI)拨号对室内机(对应的WIFI)的设备进行呼叫,室内机收到呼叫之后将对收到的数据进行UDP广播的转发,手机(连接对应的WIFI)收到视频流之 ...
- Android 实时录音和回放,边录音边播放 (KTV回音效果)
上一篇介绍了如何使用Mediarecorder来录音,以及播放录音.不过并没有达到我的目的,一边录音一边播放.今天就讲解一下如何一边录音一边播放.使用AndioRecord录音和使用AudioTrac ...
- IOS关于录音,播放实现总结
//音频录制(标准过程5,9更新) 准备:导入AVFoundation框架及头文件 1 设置会话类型,允许播放及录音AVAudioSession *audioSession = [AVAudioSes ...
- Android开发教程 录音和播放
首先要了解andriod开发中andriod多媒体框架包含了什么,它包含了获取和编码多种音频格式的支持,因此你几耍轻松把音频合并到你的应用中,若设备支持,使用MediaRecorder APIs便可以 ...
- Android平台下实现录音及播放录音功能的简介
录音及播放的方法如下: package com.example.audiorecord; import java.io.File; import java.io.IOException; import ...
- 一步步实现windows版ijkplayer系列文章之三——Ijkplayer播放器源码分析之音视频输出——音频篇
一步步实现windows版ijkplayer系列文章之一--Windows10平台编译ffmpeg 4.0.2,生成ffplay 一步步实现windows版ijkplayer系列文章之二--Ijkpl ...
- Android 录音和播放
今天工作上需要做一个一边录音一边播放的功能,大致原因是有一个外部设备输入音频到我们机器,然后我们机器需要马上把音频播放出来.所以了解了一些有关录音和播放的知识.接到这个任务的第一反应就是看看Andro ...
- AudioUnit录音和播放同时进行的一些注意点
录音(播放)和暂停 -(void)start { self.soundTotalLength = 0.0f; if (!self.unitHaveStart) { NSError *error = n ...
- [Android] 录音与播放录音实现
http://blog.csdn.net/cxf7394373/article/details/8313980 android开发文档中有一个关于录音的类MediaRecord,一张图介绍了基本的流程 ...
随机推荐
- UVA 529 Addition Chains(迭代搜索)
Addition Chains An addition chain for n is an integer sequence with the following four propertie ...
- Linux红黑树(二)——访问节点
核心对红黑树使用两点说明 1.头文件 <Documentation/rbtree.txt> Linux's rbtree implementation lives in the file ...
- Android菜鸟的成长笔记(14)—— Android中的状态保存探究(上)
原文:[置顶] Android菜鸟的成长笔记(14)—— Android中的状态保存探究(上) 我们在用手机的时候可能会发现,即使应用被放到后台再返回到前台数据依然保留(比如说我们正在玩游戏,突然电话 ...
- [Android学习笔记]Fragment使用
一.android.app.Fragment 与 android.support.v4.app.Fragment 区别 support.v4.app.Fragment是为了给低版本Android使用的 ...
- java面向对象下:Java数据库编程
19.Java数据库编程: JDBC概述: JDBC(Java Database Connection)是java中提供的一套数据库编程API,它定义了一套用来访问数据库的标准Java类 ...
- MySQL字符集编码
MySQL字符集编码总结 之前内部博客上凯哥分享了一篇关于mysql字符集的文章,之前我对mysql字符集一块基本没有深究过,看到凯哥文章后有些地方有点疑惑,遂自己去看了mysql的官方文档,并參考了 ...
- 如何得到动态链接库的输出函数tdump命令(225篇博文)
有的时候,我们需要查看一个动态链接库的输出函数列表,有很多软件可以满足此要求,比如说 exeScope.不过,去下载一个软件总归是很麻烦,Delphi 本身就自带一个类似的工具,那就是 tdump.e ...
- python转换时间戳和日期时间格式的转换
[steven@txzxp2 seccenter]$ python Python 2.7.5 (default, Jul 8 2013, 09:48:59) [GCC 4.8.1 20130603 ...
- sqlplus登录、连接命令
经常使用: sqlplus username/password 如:普通用户登录 sqlplus scott/tiger sqlplus username/password@net_service ...
- [Cocos2d-x]随机数
Cocos2d-x为我们提供了生成随机数的宏:CCRANDOM_0_1() 具体定义如下: /** @def CCRANDOM_0_1 returns a random float between 0 ...