You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by be...@apache.org on 2013/06/15 01:19:54 UTC
git commit: update wp7 AudioPlayer.cs
Updated Branches:
refs/heads/master 5d23b41cd -> ecdfc2c55
update wp7 AudioPlayer.cs
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/commit/ecdfc2c5
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/tree/ecdfc2c5
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/diff/ecdfc2c5
Branch: refs/heads/master
Commit: ecdfc2c55f12d8b450fcbdda315ff82ccbf9a16e
Parents: 5d23b41
Author: Benn Mapes <be...@gmail.com>
Authored: Fri Jun 14 16:19:43 2013 -0700
Committer: Benn Mapes <be...@gmail.com>
Committed: Fri Jun 14 16:19:43 2013 -0700
----------------------------------------------------------------------
src/wp7/AudioPlayer.cs | 41 ++++++++++++++++++++++++++++++++++-------
1 file changed, 34 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-media/blob/ecdfc2c5/src/wp7/AudioPlayer.cs
----------------------------------------------------------------------
diff --git a/src/wp7/AudioPlayer.cs b/src/wp7/AudioPlayer.cs
index a83be5b..882eb96 100644
--- a/src/wp7/AudioPlayer.cs
+++ b/src/wp7/AudioPlayer.cs
@@ -27,6 +27,7 @@ using System.Windows.Resources;
namespace WPCordovaClassLib.Cordova.Commands
{
+
/// <summary>
/// Implements audio record and play back functionality.
/// </summary>
@@ -62,6 +63,7 @@ namespace WPCordovaClassLib.Cordova.Commands
#endregion
+
/// <summary>
/// The AudioHandler object
/// </summary>
@@ -77,6 +79,7 @@ namespace WPCordovaClassLib.Cordova.Commands
/// </summary>
DispatcherTimer dtXna;
+
/// <summary>
/// Output buffer
/// </summary>
@@ -128,6 +131,7 @@ namespace WPCordovaClassLib.Cordova.Commands
this.id = id;
}
+
/// <summary>
/// Destroys player and stop audio playing or recording
/// </summary>
@@ -194,8 +198,26 @@ namespace WPCordovaClassLib.Cordova.Commands
this.recorder.BufferDuration = TimeSpan.FromMilliseconds(500);
this.buffer = new byte[recorder.GetSampleSizeInBytes(this.recorder.BufferDuration)];
this.recorder.BufferReady += new EventHandler<EventArgs>(recorderBufferReady);
- this.memoryStream = new MemoryStream();
- this.memoryStream.InitializeWavStream(this.recorder.SampleRate);
+ MemoryStream stream = new MemoryStream();
+ this.memoryStream = stream;
+ int numBits = 16;
+ int numBytes = numBits / 8;
+
+ // inline version from AudioFormatsHelper
+ stream.Write(System.Text.Encoding.UTF8.GetBytes("RIFF"), 0, 4);
+ stream.Write(BitConverter.GetBytes(0), 0, 4);
+ stream.Write(System.Text.Encoding.UTF8.GetBytes("WAVE"), 0, 4);
+ stream.Write(System.Text.Encoding.UTF8.GetBytes("fmt "), 0, 4);
+ stream.Write(BitConverter.GetBytes(16), 0, 4);
+ stream.Write(BitConverter.GetBytes((short)1), 0, 2);
+ stream.Write(BitConverter.GetBytes((short)1), 0, 2);
+ stream.Write(BitConverter.GetBytes(this.recorder.SampleRate), 0, 4);
+ stream.Write(BitConverter.GetBytes(this.recorder.SampleRate * numBytes), 0, 4);
+ stream.Write(BitConverter.GetBytes((short)(numBytes)), 0, 2);
+ stream.Write(BitConverter.GetBytes((short)(numBits)), 0, 2);
+ stream.Write(System.Text.Encoding.UTF8.GetBytes("data"), 0, 4);
+ stream.Write(BitConverter.GetBytes(0), 0, 4);
+
this.recorder.Start();
FrameworkDispatcher.Update();
this.SetState(PlayerState_Running);
@@ -284,7 +306,7 @@ namespace WPCordovaClassLib.Cordova.Commands
{
this.player.Stop(); // stop it!
}
-
+
this.player.Source = null; // Garbage collect it.
this.player.MediaOpened += MediaOpened;
this.player.MediaEnded += MediaEnded;
@@ -312,7 +334,7 @@ namespace WPCordovaClassLib.Cordova.Commands
{
using (BinaryReader br = new BinaryReader(fileResourceStreamInfo.Stream))
{
- byte[] data = br.ReadBytes((int)fileResourceStreamInfo.Stream.Length);
+ byte[] data = br.ReadBytes((int)fileResourceStreamInfo.Stream.Length);
string[] dirParts = filePath.Split('/');
string dirName = "";
@@ -555,12 +577,17 @@ namespace WPCordovaClassLib.Cordova.Commands
/// <returns></returns>
private void SaveAudioClipToLocalStorage()
{
- if (this.memoryStream == null || this.memoryStream.Length <= 0)
+ if (memoryStream == null || memoryStream.Length <= 0)
{
return;
}
- this.memoryStream.UpdateWavStream();
+ long position = memoryStream.Position;
+ memoryStream.Seek(4, SeekOrigin.Begin);
+ memoryStream.Write(BitConverter.GetBytes((int)memoryStream.Length - 8), 0, 4);
+ memoryStream.Seek(40, SeekOrigin.Begin);
+ memoryStream.Write(BitConverter.GetBytes((int)memoryStream.Length - 44), 0, 4);
+ memoryStream.Seek(position, SeekOrigin.Begin);
try
{
@@ -586,7 +613,7 @@ namespace WPCordovaClassLib.Cordova.Commands
//TODO: log or do something else
throw;
}
- }
+ }
#region Xna loop
/// <summary>