Part 20: Recording an Audio Wav File

Play Part 20: Recording an Audio Wav File
Sign in to queue

Description

Source Code: https://aka.ms/absbeginnerdevwp8
PDF Version: https://aka.ms/absbeginnerdevwp8pdf

In this lesson we'll write the code required to record the custom sound. We'll employ the Coding4Fun Toolkit to help make this easier, but we'll still need to understand things like MemoryStreams and the phone's IsolatedStorage.

Here's our game plan in this lesson:

  1. We'll modify the ToggleButton wiring up event handler methods to the Checked and Unchecked events.
  2. We'll use the MicrophoneRecord class in the Coding4Fun Toolkit's Audio namespace to begin and stop the recording process.
  3. When we stop recording, we'll need to temporarily save the sound stored in the phone's memory to a location on disk so it can be played back or saved permanently.
  4. We'll add a MediaElement control so we can enable playback of the sound.
  5. Manage the state of the Play sound button, turning it off and on depending on the recording action of the user.

Let me just say that this is perhaps one of the most challenging lessons in this entire series because it deals with some slightly more advanced material. You should embrace this ... you only learn when you struggle, and challenging yourself with difficult concepts will help you grow faster. Be sure to not only watch this video, but also read the MSDN articles that I reference for more information. So put on your thinking cap and let's get started.

 

1. Modify the ToggleButton Control wiring up Event Handler Methods

Edit the XAML code on the RecordAudio.xaml page for the ToggleButton as follows:

Generic Episode Image

In lines 39 and 40 we wire up method handlers for the two states of the ToggleButton.

 

2. Create a private instance of the Coding4Fun.Toolkit.Audio.MicrophoneRecord class

In the RecordAudio.xaml.cs file, add the following line of code:

Generic Episode Image

 

We create a new private instance of the MicrophoneRecorder class, and use the hover-over-the-blue-dash technique to add a using statement for the Coding4Fun.Toolkit.Audio namespace.

Now, we can start and stop the MicrophoneRecorder by adding code to the ToggleButton's Checked and Unchecked event handler methods:

 

Generic Episode Image

 

3. Saving the sound data collected by the MicrophoneRecorder into a file

As we're recording, the MicrophoneRecorder object is collecting the sound information in a buffer. A buffer is just a pocket of memory devoted to storing data. Buffers are typically used when there is a difference between the rate at which data is received and the rate at which it can be processed, or in the case that these rates are variable. So, it may take us 10 seconds to record a 10 second sound and during that time data is being added to the buffer. That said, the computer could process that data in a fraction of a second. The buffer is just a queue ... we can write the data at one rate of speed while reading it at another rate of speed. In programming, buffers are usually used between physical hardware and software, or when moving data from memory to disk and back, or data from memory to a network connection and back. I'm not a computer science guy, so I just think of a buffer as a bucket that you slowly collect things in until you're ready to work with the entire bucket at one time. So, I'm collecting shells on the beach and placing them into my bucket. Once I get a full bucket, I start processing them, deciding which to keep and which to throw away. I collect over a long period of time, then once I've filled my bucket, I process very quickly. That's how I think of a buffer.

When we call the Stop() method, the MicrophoneRecord stops adding sound information, but is holding that data in memory, in a buffer and NOW we need to process the data in the buffer. In this case, when I use the term "process" what I mean is that I want to grab the sound data out of the buffer and place it as a WAV file into a temporary file.

Once it's in a file sitting on my Phone's storage, I'll be able to hand that file over to a MediaElement and direct it to play that temporary WAV file. If the user wants to keep the file, I can re-name it and store it permanently.

So, let's talk about storing files on a Windows Phone. The storage space on the phone is partitioned into isolated areas. Each app installed on the phone gets one of these isolated areas. I use the term "isolated" because one app can't look at the storage area of another app. This is for security ... one app can't rummage through your photos or notes or other secret data and upload it to a secret malicious server or corrupt it in some evil way.

This isolated permanent storage area that's dedicated to your app is called IsolatedStorage. It's just a tidy way of keeping each app's data safe since each app is only able to write and read from its own storage area.

So, back to the problem at hand ... the MicrophoneRecorder object has a bunch on data sitting in a buffer in memory, a MemoryStream object. My job is to save that data from the MemoryStream to a file—a temporary file—in IsolatedStorage. To accomplish this, I'll create a helper method that will take a MemoryStream as an input parameter and then in the body of the helper method, I'll create a new file in IsolatedStorage and then dump all the MemoryStream buffer data into that file.

That's the plan, let's build it:

Generic Episode Image

 

As the screenshot indicates, the input parameter is of type MemoryStream and will need a using statement to reference System.IO.

Next, we'll employ a different type of using statement:

 

Generic Episode Image

 

In this context, the using statement will create a context for an instance of System.IO.IsolatedStorage.IsolatedStorageFile. Any code inside of the code block defined by the using statement will have access to the isoStore variable. Once the flow of execution leaves the closing curly brace, the isoStore variable will be disposed from memory properly.

You use this using syntax when you want to work with classes that implement IDisposable ... typically these are managed types in the .NET Base Class Library (or in our case, the Windows Phone API) that access UNMANAGED resources. So the primary use of the IDisposable interface is to release unmanaged resources. The garbage collector automatically releases the memory allocated to a MANAGED object when that object is no longer used. That said, it is not possible to predict when garbage collection will occur. Furthermore, the garbage collector has no knowledge of UNMANAGED resources such as window handles, or open files and streams. The danger is that two or more processes (apps) attempt to access the same resources at the same time and cause an unrecoverable error condition. Types implementing IDisposable handle these scenarios correctly. For a more complete explanation of these topics:

using Statement (C# Reference)
https://msdn.microsoft.com/en-us/library/yh598w02.aspx

IDisposable Interface
https://msdn.microsoft.com/en-us/library/system.idisposable.aspx

The IsolatedStorageFile class provides methods that help you manage the files and folder for use by your app. We use the GetUserStoreForApplication() to retrieve the IsolatedStorage area for just our app.

Next, we'll grab the buffer and attempt to create a file in our IsolatedStorage area:

 

Generic Episode Image

 

In line 69, I add a line of code that will retrieve values from the buffer (passed in to the helper method) and convert it to the format of a wav (audio) file. As you can see, the MemoryBuffer doesn't implement this method. Instead, we want to use an extension method from the Coding4Fun.Toolkit.Audio.Helpers namespace. So, in order to apply this extension method, we'll add another using statement at the top of our code file:

 

Generic Episode Image

 

An extension method in .NET allows you to attach a method to any type. So, I could add some utilities to the int or string or, in this case, the System.IO.MemoryStream. The extension method allows you to work with the members of that type just like any public method could. For more information on extension methods, and how to create your own, check out:

https://msdn.microsoft.com/en-us/library/vstudio/bb383977.aspx

Note: this is an advanced topic ... as long as you understand what they do and what purpose they serve, that's enough for now. Later you can learn how to create your own.

Ok, so now we have the buffer in wav (audio) format, we just need to actually put it into a new file on the device's IsolatedStorage area:

 

Generic Episode Image

 

(1) We create a temporary name for the wav file. We may discard this in the future (should the user hit the Record button again).
(2) The CreateFile() method creates a file on the file system using the name we pass in (line 73, above), and gives us back a reference to that we can use to write to.
(3) Now that we have an empty file to write to, we'll write the data stored in the bytes variable containing our sound. The Write() method's second and third parameters allows us to specify a portion of the sound data we want to write ... in this case, we'll write the entire file from the beginning (0) to the end (bytes.Length).

 

4. Add a MediaElement to play the new temporary file

In the RecordAudio.xaml file, beneath the ContentPanel grid control, we'll add a MediaElement control, give it a name, and set AutoPlay to false:

Generic Episode Image

Back in the RecordAudio.xaml.cs, we'll programmatically set the source of our new MediaElement to our new temporarily sound file:

Generic Episode Image

Now we're ready to play the sound file ... we just need to wire-up the event handler for the Play button.

 

5. Handle the Play button's Click Event to Test the Sound

In the RecordAudio.xaml file, in the definition for the Button element with the content "Play", we'll add a Click event handler called "PlayAudioClick":

Generic Episode Image

Navigate to the new event handler and add the following line of code to call the Play() method of the MediaElement control:

Generic Episode Image

At this point we have it all wired up, but it's not pretty ... it's pretty fragile ... so we'll need to comb back through this and program defensively. We'll do that later in this lesson.

For now, let's test our app. We've written a lot of code and, due to the nature of the functionality we've created, it wasn't possible to test it in small parts. We had to implement it all then test it to see where the problems pop up.

 

6. Declaring a Microphone capability for the app

Run the app, click the microphone icon in the application bar, then click the Record ToggleButton:

Generic Episode Image

 

When you click Record one of two things probably happened ... either the app disappeared silently (no error message), or you'll get an exception, depending on which version of the Coding4Fun Toolkit you're using. The reason this doesn't work is because we do not have permission to use the phone device's microphone. To request permission to use the microphone, we need to declare a capability in our WMAppManifest.xml file.

In Windows Phone, you have to request permissions to use certain device capabilities. One purpose of this is to notify the user just how we intend to use their device. They may grow suspicious if our app wants to use their geolocation or their camera when that's not the purpose of our app.

The way to gain access to the capabilities of the phone's hardware is to open up the WMAppManifest.xml file and go to the second tab, "Capabilities":

 

Generic Episode Image

 

  1. Open up the WMAppManifest.xml file
  2. Choose the second tab, Capabilities
  3. Add a checkmark next to the ID_CAP_MICROPHONE capability

If we re-run the app and go through the same set of steps, it should work. Note: to actually record sound in the Phone Emulator, you will need a working microphone hooked up to the computer. Make sure the mic works prior to starting this so that you can verify that it is not the source of any problems you might encounter:

 

Generic Episode Image

 

I think the biggest issue at this point is that Angel the code is pretty fragile and easily broken ... if we were to click the play button and immediately click the record button again, we could probably break the app, and (b) we don't have any visual feedback to let the user know what worked and what didn't, and (c) we are not actually saving the sound permanently, nor are we allowing the user to select a name for the new sound. We'll fix all of these in due time.

For now, let's focus on improving the quality of the code by adding defensive programming statements.

 

7. Add defensive programming statements to guard against potential exceptions

First, in the SaveTempAudio helper method, we'll make sure that there's actually data in our buffer before we attempt to create a file and fill it up with the buffer's contents:

 

Generic Episode Image

 

Next, I want to guard against the possibility that the MediaElement is currently playing when the user taps the ToggleButton to record a sound. To do that, I'll refactor my code creating the IsolateStorageFileStream as a private member of the class:

 

Generic Episode Image

 

Now, I'll add code to determine whether the _audioStream is empty. If it's not that means I have data that needs to be saved, then I need to empty it out. While I'm there, I'll make sure the MediaElement is no longer playing a sound, and its Source property is set to null. This will release any hold the MediaElement may have on the _audioStream from a previous try. It's possible that the MediaPlayer will keep a reference to the _audioStream from a previous recording, and I want it to release that reference before I try to create a new file using the same variable name _audioStream:

 

Generic Episode Image

 

  1. Here I check to see whether _audioStream is null. If it's not, then I need to make sure that we're not in the middle of using the _audioStream in playback mode. In lines 74 and 75 I release the hold that the MediaElement has on the _audioStream, then ...
  2. I call dispose on the _audioStream. That should properly release any resources _audioStream is using. It's now ready to be re-populated with a newly created file handle.
  3. Here I re-work the code ... I don't need to create a new instance of _audioStream ... it's been cleaned out and all resources have been released. So, I can merely set _audioStream to a new file reference.

Now I want to think about how I create and reference the temporary file name. I want to make sure to not leave old temporary files around since they could clutter my apps IsolatedStorage area much like extra files take up too much space on our hard drives. The exception here is that your IsolatedStorage is much smaller than a hard drive, and audio files can be large. So, first I'll move it's declaration to a private member variable (line 24, below):

 

Generic Episode Image

 

Next, I'll replace the:

var tempFileName = "tempWav.wav";

... with the following:

 

Generic Episode Image

 

  1. If a temporary file already exists on the user's device from a previous recording attempt, we want to remove that file calling the .DeleteFile() method.
  2. We want to give the file a unique name and so we use the DateTime.Now.ToFileTime() to give it a unique name down to the second. That should be sufficient for our purposes.

Next, I want to disable the Play button when recording. That simple state management should make our lives as developers easier and reduce the possibility that the user is able to corrupt something. I'll give the Button the name "PlayAudio":

 

Generic Episode Image

 

Next, I'll perform some state management in the ToggleButton's event handlers:

Generic Episode Image

  1. When I start recording, I'll disable the PlayAudio button, and ...
  2. When I stop recording, I'll enable the PlayAudio button.

 

Recap

To recap, the big take aways from this lesson include utilizing the Coding4Fun Toolkit's Audio features to greatly reduce the complexity of using the Phone's microphone to record a sound. If you want to peek and see what it does, you can search for the full name of the class in Bing to find a code listing on Codeplex:

http://coding4fun.codeplex.com/SourceControl/changeset/view/79216#1425409

We learned about the other using statement in C# to properly dispose of managed classes that work with unmanaged resources. We learned about the function of buffers as a means of collecting data at one rate that could be processed at a different rate. We used the buffer built into the Coding4Fun MicrophoneRecorder class and retrieved the buffer to save it into a file on the device's storage. We learned about IsolatedStorage and how it protects each application's storage area keeping it private from the other apps on the system. We briefly learned about extension methods as we used one that was implemented in the Coding4Fun Audio Helpers namespace and, finally, we practiced some defensive programming techniques to ensure that our app can handle unique situations or edge cases.

Embed

Download

The Discussion

  • User profile image
    zApp

    THE MOST EFFECTIVE SERIES ON CHANNEL9! Bob's series inspired me to develop. I've publish 2 apps so far. Working on my third while watching your latest videos. Feels like we're in a room programming together. Thanks Bob for keeping me company, inspiring, and educating us all.

  • User profile image
    wsantosf

    Bob

    Love the tutorial format - great when you want to read it at your own pace, and audio isn't convenient.

    Feedback: I believe you have the wrong image referred by the lines:

    "1) Here I check to see whether _audioStream is null. If it's not, then I need to make sure that we're not in the middle of using the _audioStream"

    items 1 through 3 seem to refer to the new code, but screenshot shows old one.

    Thanks to you and your minions for the great series.

  • User profile image
    BobTabor

    @zApp: Wow, that's quite a statement.  I think you're being way too kind, but thank you.

    @wsantosf: Hmm... I think you're right.  I missed a screenshot somehow.  Publishing in text along with video was much more challenging than I first believed.  Thank you for bringing this to my attention.

    May I ask ... did you watch the video AND read?  Or did you just read the article?  Just would like to get your insight on how you use both the text and video together (for my own future reference... to make it better in the future).  Do the discrepancies between text and video pose a problem for you?  (I mean, I don't stick with the script always in the video.)

    Finally, just to be clear, I'm the minion here.  I have no minions of my own.  I've got to figure out how to get some minions.  Tongue Out

  • User profile image
    Muhammad​Faizan

     private void SaveTempAudio(MemoryStream buffer)
            {
                using (IsolatedStorageFile isoStorage = new IsolatedStorageFile.GetUserStoreForApplication())
                {
    
                }
            }


    The Code you see, i am having problem here, GetUserStoreForApplication is coming up with Blue wavy line underneath it. the error is : "    'System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication()' is a 'method' but is used like a 'type' "

    Please help me with this issue,
    I am loving your series and following it along, will surely give you reference of some new app that i'll make in future Smiley

  • User profile image
    Muhammad​Faizan

    @MuhammadFaizan: Fixed it, i was using new keyword Tongue Out

  • User profile image
    BobTabor

    @MuhammadFaizan: Glad you figured it out.  I was stumped and was putting off re-doing this example to help you figure it out.  Tongue Out

  • User profile image
    Quyen Ha

    This series is the best window phone 8 resources for me to start writing WP8 apps from the bottom up.
    I actually have 2 questions in this lesson :
    1. what is var ? and why do you use it in
    var bytes = buffer.GetWavAsByteArray(_recorder.SampleRate);
    2. there is :
    _tempFileName = string.Format("{0}.wav",DateTime.Now.ToFileTime());
    I have no idea why you set format for _tempFileName. I guess you want to keep track of what records you recorded.
    Hope you can answer my questions. English is my second language. I may have wrong spelling words and grammars. Thank you for great work.

  • User profile image
    Clint

    @Quyen Ha: var is a lazy way of letting the compiler figure out what the variable's type is. 

    doing byte[] bytes = buffer.GetWavAsByteArray(_recorder.SampleRate); is the same thing.

    for the temp file name, reason why in this instance I decided to leverage DateTime.Now is it is unique enough of a file name and lets us debug knowing a bit about that file quickly.  I could have used something called a GUID (global unique identifier) but that doesn't help me quickly sort / visually check what files are what.

  • User profile image
    Quyen Ha

    very clear explanation. Thanks, Clint.
    I want to write a bedtimeteller app on window phone. And I decided to use your microphone code for my app. I wonder that is using Code4Fun the only way to get microphone to work. I'm worrying about buffer memory because my recording stories are about 15-20 minutes long. I'm afraid that it will use too much memory resources to store such large files before being used and deleted.

  • User profile image
    Clint

    @Quyen Ha: nope, just a nice pretty wrapper.  http://coding4fun.codeplex.com has all the source.  I think you'll want to do a lot of testing.  I think you'll have to experiment and see if you can't shove the buffer straight into a filestream.  A 20min wav is pretty big however.  This should be pretty easy to mock up, just a lot of testing for all the scenarios

  • User profile image
    Wilfre

    Hi Bob and Clint:

    I'm having a problem: Every time that I run the app and click the microphone button in the app bar this exception gets thrown but I'm not sure why:

    An exception of type 'System.UnauthorizedAccessException' occurred in Coding4Fun.Toolkit.Audio.DLL but was not handled in user code

     

    Hope you guys can help me, thanks

  • User profile image
    Clint

    @Wilfre: See step 6, you need to add in the capability for the program to use the microphone.  The application proper authorization to access that without that box checked.

  • User profile image
    Wilfre

    THANK YOU CLINT!

  • User profile image
    Harsh Shah

    I get an error when I run the app. When I click on Record Toggle Button, it gets active and when I tap on it again, the app crashes. Error:

    An exception of type 'System.ArgumentNullException' occurred in AppName.DLL but was not handled in user code

    If there is a handler for this exception, the program may be safely continued.

  • User profile image
    Clint

    @Harsh Shah: going to need more detail to help you out on this.  Either create a new ticket over at https://absolutebeginner.codeplex.com/workitem/list/basic with the project zipped up or compare your solution with ours.  Something wasn't started or initialized in your application.

  • User profile image
    KasunKV

    Hey Bob &Clint,

    Is there any way to convert the stream from the mic to mp3 format? or else convert the .wav file we create to .mp3 format?

  • User profile image
    Clint

    @KasunKV: with the framework for WP8, no.  Windows Store can do mp4 audio files directly I believe.

  • User profile image
    KasunKV

    @Clint: So clint, if i wanted to convert the stream or the .wav file created to mp3 what would i have to do? Can you give some pointers. There are some apps in the Windows Phone Store that performs such conversion, How are they doing it? are they creating the algorithms necessary to do that by them self or do they use a 3rd party tools? 

  • User profile image
    Clint

    @KasunKV: Mp3 conversion stuff is past absolute beginner.  We are trying to keep comments to the video at hand.  I'd recommend asking the questions at www.stackoverflow.com or https://dev.windowsphone.com

  • User profile image
    KasunKV

    @Clint: Sorry Clint, if i stepped out of line.. My apologies. Thanks for the pointers you gave me.. and Thanks for the video series as well. Your previous video series on WP7, Thats how i got started developing WP apps.. Downloaded this series for additional info.. Great Job guys.. keep it up.. Smiley

     

  • User profile image
    Clint

    @KasunKV: it was a great request and wasn't out of line at all.  I just have to play the bad guy from time to time to keep stuff on topic Smiley

  • User profile image
    Heena

    Hi Bob, I want to ask that if I have recorded sound as .mp3 & don't set audioPlayer.setSource(audioStream) directly inside where I write the bytes on tempFileName instead i want to read it using the tempFileName from isostorage on play button click.

    I used to do like
    using (IsolatedStorageFile isostorage = IsolatedStorageFile.GetUserStoreForApplication())
    {
    using(var stream= new IsolatedStorageFileStream (tempFileName,FileMode.Open,isostorage))
    {
    audioPlayer.SetSource(stream);
    }
    }

  • User profile image
    Heena

    I missed to complete my question above.
    So after reading stream like & setting source to audioplayer it is not playing the sound.
    But giving me the naturalDuration of recording.
    Any suggestion ???

  • User profile image
    Clint

    @Heena: I'm not 100% sure what you're trying to do. 

  • User profile image
    Heena

    Ok I think I made my question complicated. Apologies.

    Simply when I read audioStream like

    using (IsolatedStorageFile isostorage = IsolatedStorageFile.GetUserStoreForApplication())
    {
    using(var stream= new IsolatedStorageFileStream (tempFileName,FileMode.Open,isostorage))
    {
    audioPlayer.SetSource(stream);
    }
    }

    it is not playing the sound but shows its natural duration.
    Hope you will get it now.

  • User profile image
    Heena

    I got solution of my issue I didn't set the flag of media element i.e., autoplay="True".
    It's working now :)

  • User profile image
    Clint
    @Heena: awesome. Way to debug through it!
  • User profile image
    Heena

    Hello, hope I am not asking silly questions.
    One more help I need, using MicrophoneRecorder class which default format is recorded.

    As I named tempFileName with extension .mp3 or .m4a or .wav it's playing fine.
    But if I used tempFileName without any of these extension, it's also playing the sound. So can you tell me by default MicrophoneRecorder uses which extension to save the audio recorded in wp8.

  • User profile image
    Clint

    @Heena: default for Windows Phone 8 is raw audio.  The Coding4Fun library that we are using here helps abstract a away some of the harder stuff and helps make the byte array into a proper WAV file.  Since you (the programmer) knows what the file is, the extension doesn't matter really.  The file is saved as a WAV in its data and the MediaElement knows how to read that file Smiley

  • User profile image
    Heena

    Thanks for the explanation, its really helpful.
    I want to save my audio in .m4a format so if i do so, will it work???
    also keeping autoplay = true, media element plays the sound whenever i am navigating to that page where it is defined.
    Any solution??

  • User profile image
    Clint

    @Heena: I only did a wav save as doing a wav file with a raw buffer is easy to implement.  I know WinRT (Window Store Applications) can save as a M4A but they have an included encoder to do this.  You'd have to do a transcoder for do that.

    for doing media playback while autoplay = true, if the object has a valid source, you expressly told it to play.  Null out the source should do it or turn off autoplay

  • User profile image
    StormMagnus

    Bob & Clint, amazing tutorials and I am enjoying going through them. I have completed all lessons to this point but when I record custom audio and save it, the Custom icons do not appear. I don't know if the JSON is not serializing properly or saving it correctly. I've tried going through my code line by line short of strict copy/paste of finished code. I'm using MVS 2013 Pro RC and wonder if that caused issue? If you could point me to where this error should be, it would be greatly appreciated.

    - Monte MacDonald

  • User profile image
    Clint

    @StormMagnus: I'd put a bunch of break points around saving data and loading it in any spot.  My gut thinks you're not reloading the data on the main page after you save it.  Look at our sample.  This sample just goes over recording audio, not hooking up the rest of the stuff like what your outlining here.

  • User profile image
    Leandros

    Very nice tutorial, easy to understand and to follow. Thank you guys.

  • User profile image
    MCUGuy

    Hey guys need help here:

     private void RecordAudioChecked(object sender, RoutedEventArgs e)
    {
    PlayAudio.IsEnabled = false;
    _recorder.Start();
    }
    
    private void RecordAudioUnchecked(object sender, RoutedEventArgs e)
    {
    _recorder.Stop();
    SaveTempAudio(_recorder.Buffer);
    PlayAudio.IsEnabled = true;
    ApplicationBar.IsVisible = true;
    }

    I couldn't get Hyper-V running on my machine so I debug on a Lumia 620. When I click on the Record button I get the following exception in VS2012:

    An exception of type 'System.NullReferenceException' occurred in Sound Board.DLL but was not handled in user code

    On the phone, recording does not start, Record button does not toggle, Play button does not grey out and the exception occurs.

    The debugger breaks at the first instance of PlayAudio.IsEnabled. In the editor, I get no squigglies, and when I "go to definition" (F7) from the RecordAudio.xaml.cs file it takes me to my RecordAudio.xaml right where it's declared:

    <Button x:Name = "PlayAudio" ......./>

    Commenting out the PlayAudio.IsEnabled = true/false lines works fine and records and plays back normally.

    Any clues??

    ********************* FIXED *****************


    Deleted all instances of PlayAudio from both files

    Saved and compiled

    Used Build > Clean Solution (whatever that does)

    Re-wrote those sections of code

     

    I'm glad it's fixed but without knowing what happened I feel like I haven't learned!!

     

  • User profile image
    LocTho

    thanks you a lot, now i can know memory in windowsphone. I love your series

  • User profile image
    laithabualf​oul
    hi

    i have problem with web soap services in windows phone 8
    in this web service i have AuthHeader then
    when i need call any method i can't

    i try this code :

    MobileService.AuthHea
    hi 
    
    i have problem with web soap services in windows phone 8
    in this web service i have AuthHeader then 
    when i need call any method i can't
    
    i try this code :
    

    MobileService.AuthHeader WS = new MobileService.AuthHeader();
    WS.Username = "test";
    WS.Password = "test";

    MobileService.ServiceSoapClient Phone_WS = new MobileService.ServiceSoapClient();

    Phone_WS.checkUserCompleted += Phone_WS_checkUserCompleted;
    Phone_WS.checkUserAsync("90003276", "5467612");

    web servis must return this xml when the condition is true
    nullplz any one help me ....
  • User profile image
    laithabualf​oul

    hi

    i have problem with web soap services in windows phone 8
    in this web service i have AuthHeader then
    when i need call any method i can't

    i try this code :

    MobileService.AuthHea

    hi 
    
    i try this code :
    

    MobileService.AuthHeader WS = new MobileService.AuthHeader();
    WS.Username = "test";
    WS.Password = "test";

    MobileService.ServiceSoapClient Phone_WS = new MobileService.ServiceSoapClient();

    Phone_WS.checkUserCompleted += Phone_WS_checkUserCompleted;
    Phone_WS.checkUserAsync("90003276", "5467612");

    web servis must return this xml when the condition is true
    plz any one help me ....

  • User profile image
    BobTabor
  • User profile image
    JosepW

    I have a question.
    Won't the last temporal file created always remain? I mean, we are deleting the previous created file, but not the last one (Note: I did not watch the video, just read the article).

    In order to avoid this, I wanted to keep using the same filename all the time, but I get an OperationNotPermited exception when trying to create the file (_audioStream = new IsolatedStorageFileStream(_filename, FileMode.Create, isoStore);).
    Even if I execute the following code before:
    if (_audioStream != null)
    {
    AudioPlayer.Source = null;
    _audioStream.Dispose();
    _audioStream.Close();
    _audioStream = null;
    }

    and
    if (File.Exists(_filename))
    {
    File.Delete(_filename);
    }

    Curiously, I don't get the exception when debugging it.

    Thanks

  • User profile image
    Imtiaz

    Hi.
    I'm having a problem with the GetWavAsByteArray.
    This is my code below:

    DateTime.Now.ToFileTime());
    var bytes = buffer.GetWavAsByteArray(_recorder.SampleRate);
    _audioStream = isoStore.CreateFile(_tempFileName);
    _audioStream.Write(bytes, 0, bytes.Length);
    AudioPlayer.SetSource(_audioStream);

    I have seen that someone else in this forum has had the same problem, but the solution given by clint didn't fix my problem. This is the error i get when trying to debug:
    'System.IO.MemoryStream' does not contain a definition for 'GetWavAsByteArray' accepting a first argument of type 'System.IO.MemoryStream' could be found (are you missing a directive or an assembly reference?).

    My tutor couldn't solve the problem. Please can you give me a fix?

  • User profile image
    smoothumut

    great buffer example :)

  • User profile image
    SayyedAzim

    Hi Bob and hi Clint..

    your video series is awesome i like it very much.

    I need your help.

    I'm beginner to windows phone development.

    I'm working on application just like piano in that i want to record sound from MediaElement not from microphone device. how can i do that please tell me.

    At last thanks for your way of explanation, it's nice.  

  • User profile image
    Ahmad Dar

    Hello guys... Need ur help!
    I'm facing an error which says "GetUserStoreForApplication" is a method but used as a type. Kindly tell its remedy...

  • User profile image
    Hassaan Nasir

    Hey Bob i really love your videos...its really helpful. I just need some help in my project regarding audio recording. I am making a musical app and I want to record all media elements which are being played in a Page. For example I play a song then i play a piano over it, i want to record that all and make a song. Could you please tell me how could i do that?? I have been searching this for 2 weeks but didn't find anything. Any help would be appreciated. Thanx!

  • User profile image
    xuenhua

    Hi Bob,the recorder‘s volume is too low,when I play the record  it sounds a lot lower than the actual sound. I want to increase the record volume,how to do this?Thank you!

Add Your 2 Cents