Rahul Choudhary

Rahul Choudhary

  • NA
  • 5
  • 7.6k

how do i play mp3 file from array of bytes

Dec 27 2013 10:11 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication2
{
    class Program
    {
        public static void Main(string[] args)
        {
            string _FileName = "C:\\rah\\Enya.mp3";
            byte[] p;
            p=File.ReadAllBytes(_FileName);
            byte[] Stm = StereoToMono(p);
            
            for(int i=0;i<Stm.Length;i++)
            {
            Console.Out.WriteLine(Stm[i]);
            }
            Console.ReadKey();
                  
        }
        public static byte[] StereoToMono(byte[] input)
        {
            byte[] output = new byte[input.Length / 2];
            int outputIndex = 0;
            try
            {
                for (int n = 0; n < input.Length; n += 4)
                {
                    // copy in the first 16 bit sample
                    output[outputIndex++] = input[n];
                    output[outputIndex++] = input[n + 1];

                }
            }
            catch (Exception e)
            { return output; }
            return output;
        }


        private byte[] MonoToStereo(byte[] input)
        {
            byte[] output = new byte[input.Length * 2];
            int outputIndex = 0;
            try
            {
                for (int n = 0; n < input.Length; n += 2)
                {
                    // copy in the first 16 bit sample
                    output[outputIndex++] = input[n];
                    output[outputIndex++] = input[n + 1];
                    // now copy it in again
                    output[outputIndex++] = input[n];
                    output[outputIndex++] = input[n + 1];
                }
            }
            catch (Exception e)
            { return output; }
            return output;
        }
        

        

    }
}