Updated Branches: refs/heads/master b32ecd17a -> 2c477f436
Broke AudioFormatsHelper back into the 2 classes that use it to avoid plugin dependency Project: http://git-wip-us.apache.org/repos/asf/cordova-wp7/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-wp7/commit/2eb31bb0 Tree: http://git-wip-us.apache.org/repos/asf/cordova-wp7/tree/2eb31bb0 Diff: http://git-wip-us.apache.org/repos/asf/cordova-wp7/diff/2eb31bb0 Branch: refs/heads/master Commit: 2eb31bb04c675d145c79f8432512b205d5548472 Parents: b32ecd1 Author: Jesse MacFadyen <[email protected]> Authored: Tue Jun 11 14:25:28 2013 -0700 Committer: Benn Mapes <[email protected]> Committed: Wed Jun 12 15:16:54 2013 -0700 ---------------------------------------------------------------------- templates/standalone/Plugins/AudioPlayer.cs | 34 +++++++++++++++++--- .../standalone/Plugins/UI/AudioRecorder.xaml.cs | 22 +++++++++++-- 2 files changed, 49 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-wp7/blob/2eb31bb0/templates/standalone/Plugins/AudioPlayer.cs ---------------------------------------------------------------------- diff --git a/templates/standalone/Plugins/AudioPlayer.cs b/templates/standalone/Plugins/AudioPlayer.cs index a83be5b..6c94016 100644 --- a/templates/standalone/Plugins/AudioPlayer.cs +++ b/templates/standalone/Plugins/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,8 @@ namespace WPCordovaClassLib.Cordova.Commands /// </summary> DispatcherTimer dtXna; + + /// <summary> /// Output buffer /// </summary> @@ -128,6 +132,8 @@ namespace WPCordovaClassLib.Cordova.Commands this.id = id; } + + /// <summary> /// Destroys player and stop audio playing or recording /// </summary> @@ -194,8 +200,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 +308,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 +336,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 = ""; @@ -586,7 +610,7 @@ namespace WPCordovaClassLib.Cordova.Commands //TODO: log or do something else throw; } - } + } #region Xna loop /// <summary> http://git-wip-us.apache.org/repos/asf/cordova-wp7/blob/2eb31bb0/templates/standalone/Plugins/UI/AudioRecorder.xaml.cs ---------------------------------------------------------------------- diff --git a/templates/standalone/Plugins/UI/AudioRecorder.xaml.cs b/templates/standalone/Plugins/UI/AudioRecorder.xaml.cs index bc8ba6f..74fb846 100644 --- a/templates/standalone/Plugins/UI/AudioRecorder.xaml.cs +++ b/templates/standalone/Plugins/UI/AudioRecorder.xaml.cs @@ -122,8 +122,25 @@ namespace WPCordovaClassLib.Cordova.UI this.buffer = new byte[microphone.GetSampleSizeInBytes(this.microphone.BufferDuration)]; this.microphone.BufferReady += new EventHandler<EventArgs>(MicrophoneBufferReady); - this.memoryStream = new MemoryStream(); - this.memoryStream.InitializeWavStream(this.microphone.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.microphone.SampleRate), 0, 4); + stream.Write(BitConverter.GetBytes(this.microphone.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.duration = new TimeSpan(0); @@ -302,5 +319,6 @@ namespace WPCordovaClassLib.Cordova.UI dtXna = null; } } + } } \ No newline at end of file
