package com.example.viraj.mediaplayerapp; import android.media.MediaPlayer; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.SeekBar; import android.widget.Toast; //import static com.example.viraj.mediaplayerapp.R.raw.ashique; public class MainActivity extends AppCompatActivity { private MediaPlayer mediaPlayer; private Button playbutton; private SeekBar M_seekBar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); M_seekBar = (SeekBar) findViewById(R.id.id_seekbar); mediaPlayer = new MediaPlayer(); mediaPlayer = MediaPlayer.create(MainActivity.this, R.raw.mercy); M_seekBar.setMax(mediaPlayer.getDuration()); //-------seekbar M_seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i_879, boolean b_123) { if (b_123) { mediaPlayer.seekTo(i_879); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); //----------------seekbar //set on completion method----------------- mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mediaPlayer_mp) { int duration = mediaPlayer_mp.getDuration(); String mduration = String.valueOf(duration / 1000); Toast.makeText(getApplicationContext(), "Duration" + mduration, Toast.LENGTH_LONG).show(); } }); //---------------------------- playbutton = (Button) findViewById(R.id.MusicPlay); playbutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mediaPlayer.isPlaying()) { //stop music and give option pausemusic(); } else { startmusic(); } } }); } //create method in side of our class public void pausemusic() { if (mediaPlayer != null) mediaPlayer.pause(); playbutton.setText("PLAY MUSIC"); } public void startmusic() { if (mediaPlayer != null) { mediaPlayer.start(); playbutton.setText("PAUSE MUSIC"); } } //memory consume karta he iss liye @Override protected void onDestroy() { if (mediaPlayer != null && mediaPlayer.isPlaying()) { mediaPlayer.stop(); mediaPlayer.release(); mediaPlayer = null; } super.onDestroy(); } }
Sunday, 10 December 2017
basic play mp3 part 3
Search This Blog
Categories
Popular Posts
-
https://github.com/Enteleform/-RES-/blob/master/%5BLinks%5D/%5BAndroid%5D%20Udacity%20Curriculum.md#full-curriculum-outline Full Curri...
-
'C:\Users\viraj\AppData\Local\Android\sdk\platform-tools\adb.exe,start-server' failed -- run manually if necessary Solution ...
-
how to make crores from 1 lakh in stock markets in 1 year
Pages
how to make crores from 1 lakh in stock markets in 1 year
how to make crores from 1 lakh in stock markets in 1 year
0 comments:
Post a Comment