How to play audio from audio array on click in xml in android
<pre><code>     public void getSound(String file) {
                    MediaPlayer mp;
                        try{
                            String SoundFile=file;
                            System.out.println("Here is the File"+SoundFile);
                            mp = MediaPlayer.create(getActivity().getBaseContext(),Uri.parse("android.resource://himanshu.sound/raw/"+file)); 
                            mp.start(); 
                            System.out.println("PLAYED");
                        }catch(Exception e){
                            System.out.println("Exception-&gt;"+e);
                        }   
                }
</code></pre>

<p>This is my code file name is game.mp3 comming from assets.</p>

<p>Now I want to the audio to be played </p>

<p>This is my xml </p>

<pre><code>    &lt;ImageView
                        android:id="@+id/soundbtn"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:clickable="true"
                        android:gravity="right"
                        android:onClick="getSound"
                        android:paddingLeft="5dp"
                        android:paddingRight="15dp"
                        android:paddingBottom="5dp"
                        android:src="@drawable/audio" /&gt;



mp = MediaPlayer.create(getActivity().getBaseContext(),Uri.parse("android.resource://himanshu.sound/raw/"+file));
</code></pre>

<p>in this line i am having error </p>

<p>getActivity().getBaseContext()  i think proper thing must be there</p>
