Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AudioPlayer app
package com.aasemjs.audioplayer;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
public class MainActivity extends AppCompatActivity {
MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mp=MediaPlayer.create(this, R.raw.abc);
}
public void playSong(View v){
mp.start();
}
public void pauseSong(View v) {
mp.pause();
}
public void stopSong(View v) {
mp.stop();
mp=MediaPlayer.create(this, R.raw.abcd);
}
}
@samiaissaoui

This comment has been minimized.

Copy link

@samiaissaoui samiaissaoui commented Feb 12, 2018

it didn't work for me null pointer

@kassimjk

This comment has been minimized.

Copy link

@kassimjk kassimjk commented May 21, 2018

Check Mine Out.
public class MainActivity extends AppCompatActivity {

MediaPlayer mediaPlayer;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);


    mediaPlayer = MediaPlayer.create(this, R.raw.laugh);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();


        }
    });
}


public void play(View view) {

    mediaPlayer.start();

}

public void pause(View view) {
    mediaPlayer.pause();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment