title: How to play Base64 encoded audio in android?
body: <p>What I have tried till now :-</p>
  
  <ul>
  <li>Have a Base64 encoded String of an audio file.</li>
  </ul>
  
  <p>Now here I am trying to play like this.</p>
  
  <pre><code>public void PlayAudio(String base64EncodedString){
          try
          {
              String url = "data:audio/mp3;base64,"+base64EncodedString;
              Uri uri = Uri.parse(url);
              mediaPlayer.setDataSource(MainActivity.this, uri);
              /*mediaPlayer.prepare();*/
              mediaPlayer.start();
          }
          catch(Exception ex){
              System.out.print(ex.getMessage());
          }
      }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>private void playMp3(byte[] mp3SoundByteArray) {
          try {
              // create temp file that will hold byte array
              File tempMp3 = File.createTempFile("kurchina", "mp3", getCacheDir());
              tempMp3.deleteOnExit();
              FileOutputStream fos = new FileOutputStream(tempMp3);
              fos.write(mp3SoundByteArray);
              fos.close();
  
              // resetting mediaplayer instance to evade problems
              mediaPlayer.reset();
  
              // In case you run into issues with threading consider new instance like:
              // MediaPlayer mediaPlayer = new MediaPlayer();
  
              // Tried passing path directly, but kept getting
              // "Prepare failed.: status=0x1"
              // so using file descriptor instead
              FileInputStream fis = new FileInputStream(tempMp3);
              mediaPlayer.setDataSource(fis.getFD());
  
              //mediaPlayer.prepare();
              mediaPlayer.start();
          } catch (IOException ex) {
              String s = ex.toString();
              ex.printStackTrace();
          }
      }
  </code></pre>
  
  <p>But audio is not playing.</p>
  
  <p>May any one assist me over this.</p>