microphone - windows phone 7 Recording Issue -


i working on recording functionality in windows phone 7 app. implemented recording functionality through reference link.

it works fine @ there , in case also.

actually scenario is, in application created first page works recording screen same above referred link. , when stop recording redirected second page , saved recording in isolated storage , @ second page bound recorded sounds. @ here played recorded sounds @ works fine.

now, when m again go recording screen(first page) , starts recording. times records fine , times skip sounds during recording beep sounds , looks noise in recording , not getting recording sounds.

my code like,

public partial class nikhilrecord : phoneapplicationpage {     //xna objects record , playback     microphone mphone;      //used storing captured buffers     list<byte[]> memobuffercollection = new list<byte[]>();      //used displaying stored memos     observablecollection<memoinfo> memofiles = new observablecollection<memoinfo>();      spacetime spacetime = new spacetime();      public nikhilrecord()     {         initializecomponent();          //create new microphone , set event handler.         mphone = microphone.default;         mphone.bufferready += onmicrophonebufferready;         string filename = phoneapplicationservice.current.state["myselectedsong"].tostring();          using (isolatedstoragefile isolatedstorage = isolatedstoragefile.getuserstoreforapplication())         {             try             {                 using (isolatedstoragefilestream filestream = isolatedstorage.openfile(filename, filemode.open, fileaccess.read))                 {                     mymedia.setsource(filestream);                                            mymedia.currentstatechanged += new routedeventhandler(mediaplayer_currentstatechanged);                      filestream.close();                     filestream.dispose();                      //start recording                     onrecordbuttonclick();                 }             }             catch (exception exc)             {                 messagebox.show(exc.message);             }         }          void updaterecording(bool isrecording)         {            if (!isrecording)            {                using (isolatedstoragefile storage = isolatedstoragefile.getuserstoreforapplication())                {                   spacetime.space = storage.availablefreespace;                }            }            else            {                spacetime.space = memobuffercollection.count * mphone.getsamplesizeinbytes(mphone.bufferduration);            }            spacetime.time = mphone.getsampleduration((int)math.min(spacetime.space, int32.maxvalue));                     }         void onmicrophonebufferready(object sender, eventargs e)         {             // buffer microphone , add collection             byte[] buffer = new byte[mphone.getsamplesizeinbytes(mphone.bufferduration)];             int bytesreturned = mphone.getdata(buffer);             memobuffercollection.add(buffer);              updaterecording(true);             // continue...             if (spacetime.time > timespan.fromminutes(10))             {               stoprecording();               updaterecording(false);             }         }         void onrecordbuttonclick()         {            if (mphone.state == microphonestate.stopped)            {                // clear collection storing buffers                memobuffercollection.clear();                 // start recording                mphone.start();                mymedia.play();            }            else            {                mymedia.stop();                //mphone.stop();                popupgrid.visibility = visibility.visible;                recordgrid.opacity = 0.5;                recordgrid.ishittestvisible = false;             }             bool isrecording = mphone.state == microphonestate.started;             updaterecording(isrecording);         }         void stoprecording()         {            // last partial buffer            int samplesize = mphone.getsamplesizeinbytes(mphone.bufferduration);            byte[] extrabuffer = new byte[samplesize];            int extrabytes = mphone.getdata(extrabuffer);             // stop recording            mphone.stop();            //stop song            mymedia.stop();             // create memoinfo object , add @ top of collection            int totalsize = memobuffercollection.count * samplesize + extrabytes;            timespan duration = mphone.getsampleduration(totalsize);            memoinfo memoinfo = new memoinfo(datetime.utcnow, totalsize, duration);            memofiles.insert(0, memoinfo);             // save data in isolatedstorage             using (isolatedstoragefile storage = isolatedstoragefile.getuserstoreforapplication())            {               string[] alldirectories = storage.getdirectorynames("nikdirectory");               if (alldirectories.count() == 0)                  storage.createdirectory("nikdirectory");               try               {                  using (isolatedstoragefilestream stream = storage.createfile("nikdirectory\\" + memoinfo.filename))                  {                     // write buffers collection                     foreach (byte[] buffer in memobuffercollection)                         stream.write(buffer, 0, buffer.length);                      // write partial buffer                     stream.write(extrabuffer, 0, extrabytes);                      stream.close();                     stream.dispose();                  }                   uri url = new uri("/gallery.xaml", urikind.relative);                  navigationservice.navigate(url);                  memobuffercollection.clear();               }               catch (exception ees)               {                  messagebox.show(ees.message);                  uri url = new uri("/karaoke.xaml", urikind.relative);                  navigationservice.navigate(url);               }            }           bool isrecording = mphone.state == microphonestate.started;           updaterecording(isrecording);        } } 

so, please me out problem. heard @ somewhere have dispose objects of microphone when redirect screen. true ? or else.

please me. looking forward.

instead of using collection, should use following way read recorded bytes. should done bufferready event of microphone object.

 byte[] audiobuffer = new byte[microphone.getsamplesizeinbytes(microphone.bufferduration)];                 microphone.getdata(audiobuffer);                                  recordingstream.write(audiobuffer, 0, audiobuffer.length); 

recordingstream memorystream , should declared globally.

i not sure have used , works fine in each case. try this.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -