C
core_85
Neues Mitglied
- 0
hallo,
ich habe folgendes Problem und zwar das mein "Pause"-Button die laufende Musik nicht stoppen kann. Wäre gut wenn jem helfen kann
layout:
ich habe folgendes Problem und zwar das mein "Pause"-Button die laufende Musik nicht stoppen kann. Wäre gut wenn jem helfen kann
layout:
Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</GridLayout>
<Button
android:id="@+id/btn_prev"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/btn_prev" />
<Button
android:id="@+id/btn_next"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/btn_next" />
<Button
android:id="@+id/btn_pause"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/btn_pause" />
<Button
android:id="@+id/btn_play"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/btn_play" />
<SeekBar
android:id="@+id/seekBar_volumen"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textView_song_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/textView_song_title" />
</LinearLayout>
Code:
package net.ibasic;
import java.io.IOException;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;
public class MusicActivity extends Activity {
/** Called when the activity is first created. */
private TextView txt_song_title;
private MediaPlayer mediaPlayer;
//private int counter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/**/
Button btn_prev = (Button) findViewById(R.id.btn_prev);
Button btn_next = (Button) findViewById(R.id.btn_next);
Button btn_pause = (Button) findViewById(R.id.btn_pause);
Button btn_play = (Button) findViewById(R.id.btn_play);
SeekBar seek_volumen = (SeekBar) findViewById(R.id.seekBar_volumen);
txt_song_title = (TextView) findViewById(R.id.textView_song_title);
// counter=0;
/**/
mediaPlayer = new MediaPlayer();
/**/
btn_next.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
//counter =counter +1 ;
txt_song_title.setText(null); // Titel
try{
mediaPlayer.reset();
}
catch(Exception e){
//
}
MediaPlayer mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.song);
try {
mediaPlayer.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.start();
}});
btn_next.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
}
});
btn_prev.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
try{
mediaPlayer.reset();
}
catch(Exception e){
//
}
txt_song_title.setText(null); // Titel
try {
mediaPlayer.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.start();
}
});
btn_play.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
txt_song_title.setText(null); // Titel
MediaPlayer mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.song);
try {
mediaPlayer.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.start();
}
});
btn_pause.setOnClickListener(new View.OnClickListener(){
public void onClick(View view){
mediaPlayer.pause();
mediaPlayer.stop();
}
});
}
}