Created
June 6, 2017 13:37
-
-
Save coldyca/32e27b5944f8dd400a67653ad770c8bb to your computer and use it in GitHub Desktop.
MediaPlayer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
final MediaPlayer mp = MediaPlayer.create(this, R.raw.color_brown); | |
Button b = (Button) findViewById(R.id.play); | |
Button b2= (Button) findViewById(R.id.pause); | |
Button b3= (Button) findViewById(R.id.volumedown); | |
Button b4= (Button) findViewById(R.id.volumeup); | |
b.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Toast.makeText(MainActivity.this, "Start", Toast.LENGTH_SHORT).show(); | |
mp.start(); | |
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { | |
public void onCompletion(MediaPlayer mp) { | |
Toast.makeText(MainActivity.this, "Sfarsit de melodie", Toast.LENGTH_LONG).show(); | |
} | |
}); | |
} | |
}); | |
b2.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
mp.pause(); | |
} | |
}); | |
b3.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); | |
audio.adjustStreamVolume(AudioManager.STREAM_MUSIC, | |
AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI); | |
} | |
}); | |
b4.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); | |
audio.adjustStreamVolume(AudioManager.STREAM_MUSIC, | |
AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI); | |
} | |
});}} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment