Reputation: 888
I am creating Windows Phone 8.1 app, I have created Audio Recorder module, and converting audio stream to Base64String, but my resulting Base64String is given below:
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
For exact idea, see my code below:
public void UpdateWavHeader()
{
if (!stream.CanSeek) throw new Exception("Can't seek stream to update wav header");
var oldPos = stream.Position;
stream.Seek(4, SeekOrigin.Begin);
stream.Write(BitConverter.GetBytes((int)stream.Length - 8), 0, 4);
stream.Seek(40, SeekOrigin.Begin);
stream.Write(BitConverter.GetBytes((int)stream.Length - 44), 0, 4);
stream.Seek(oldPos, SeekOrigin.Begin);
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
string isoVideoFileName = "DemoFile.aac";
if (isf.FileExists(isoVideoFileName))
{
isf.DeleteFile(isoVideoFileName);
}
isoVideoFile = new IsolatedStorageFileStream(isoVideoFileName, FileMode.Create, IsolatedStorageFile.GetUserStoreForApplication());
isoVideoFile.Write(stream.ToArray(), 0, stream.ToArray().Length);
byte[] chunk = new byte[isoVideoFile.Length];
string base64String = Convert.ToBase64String(chunk);
}
Upvotes: 0
Views: 428
Reputation: 2233
Take a look at these two lines in your code:
byte[] chunk = new byte[isoVideoFile.Length];
string base64String = Convert.ToBase64String(chunk);
You are basicly encoding a byte array initialized to zero's.
EDIT:
Assuming you want to encode the stream you are writing to the .aac file, this should do the trick:
var chunk = stream.ToArray();
isoVideoFile = new IsolatedStorageFileStream(isoVideoFileName, FileMode.Create, IsolatedStorageFile.GetUserStoreForApplication());
isoVideoFile.Write(chunk, 0, chunk.Length);
//byte[] chunk = new byte[isoVideoFile.Length];
string base64String = Convert.ToBase64String(chunk);
Upvotes: 2