Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using below code to play recorded sound in my Windows Phone 8 application which is stored in Bytes[]. This application is for voice chat and it's working fine when i am chatting on windows phone but when i am trying to talk with android phone then i am not able to play android generated sound file and getting Error 'Ensure that the buffer length is non-zero and meets the block alignment requirements for the audio format.'

C#
private void PlayMessage_Completed(object sender, OpenReadCompletedEventArgs e)
        {
        try
            {
            if (e.Error != null)
                {
                MessageBox.Show(e.Error.Message);
                MessagePlayCleanup(e.Error.Message);
                }
            else if (e.Result.Length < 200)
                {
                // fix:  Try to parse XML and see what the error was?
                MessageBox.Show("Could not find message");
                MessagePlayCleanup("Message Play Failed");
                }
            else if (e.Result.Length < 20000)
                {
                MessagePlayCleanup("Message Too Short");
                }
            else
                {
                Message msg = (Message)e.UserState;

                ShowProgress(true, "Playing Message...");
                setButtonContent(false);
                pbPlaying.Value = 0;
                pbPlaying.Maximum = msg.Length;
                pbPlaying.IsEnabled = true;
                pbPlaying.Visibility = Visibility.Visible;

                MemoryStream data = new MemoryStream();
                PushData(e.Result, data);
                SoundEffect sound = new SoundEffect(data.ToArray(), microphone.SampleRate, AudioChannels.Mono);
                soundInstance = sound.CreateInstance();
                soundInstance.Play();
                soundStartTime = DateTime.Now;

                soundIsPlaying = true;

                data.Dispose();


Thanks in advance
Posted
Updated 4-Jul-13 21:16pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900