title: How to plot loudness vs time real time graph for audio file in android studio
body: <p>I am new to android. I have an audio file (mp3 file). I want to create an android app using android studio that plots a graph between loudness(dB) and time of the music file when it is played.How to implement this.</p>
  
  <p>PS: Implementation for the same in HTML is<br>
  <code>http://seapip.com/canvas/visualizer3/</code></p>
  
  <p>My current code in android is:</p>
  
  <p><strong>AndroidManifest.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.prateek.mediaplayer"&gt;
  
      &lt;application
          android:allowBackup="true"
          android:icon="@mipmap/ic_launcher"
          android:label="@string/app_name"
          android:supportsRtl="true"
          android:theme="@style/AppTheme"&gt;
          &lt;activity android:name=".MainActivity"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p><strong>activity_main.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context="com.example.mohit.mediaplayer.MainActivity"&gt;
  
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Play"
          android:id="@+id/play"
          android:layout_alignParentBottom="true"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Pause"
          android:id="@+id/pause"
          android:layout_alignParentBottom="true"
          android:layout_alignParentRight="true"
          android:layout_alignParentEnd="true" /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>package com.example.prateek.mediaplayer;
  
  import android.media.MediaPlayer;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  
  public class MainActivity extends AppCompatActivity {
  Button play,pause;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          play=(Button)findViewById(R.id.play);
          pause=(Button)findViewById(R.id.pause);
  
          final MediaPlayer sound=MediaPlayer.create(MainActivity.this,R.raw.media);
  
          play.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  sound.start();
              }
          });
  
          play.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  sound.pause();
              }
          });
  
      }
  }
  </code></pre>