Skip to content

Instantly share code, notes, and snippets.

@codingwithsara
Created November 27, 2018 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codingwithsara/4e4f8df688e55f969b7047fd5ed06c12 to your computer and use it in GitHub Desktop.
Save codingwithsara/4e4f8df688e55f969b7047fd5ed06c12 to your computer and use it in GitHub Desktop.
Android MusicPlayer 4
public class MainActivity extends AppCompatActivity {
private Button playBtn;
private SeekBar positionBar;
private SeekBar volumeBar;
private TextView elapsedTimeLabel;
private TextView remainingTimeLabel;
private MediaPlayer mp;
private int totalTime;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
playBtn = findViewById(R.id.playBtn);
elapsedTimeLabel = findViewById(R.id.elapsedTimeLabel);
remainingTimeLabel = findViewById(R.id.remainingTimeLabel);
// Media Playerの初期化
mp = MediaPlayer.create(this, R.raw.music);
mp.setLooping(true);
mp.seekTo(0);
mp.setVolume(0.5f, 0.5f);
totalTime = mp.getDuration();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment