Android媒体播放器无法使用按钮

Android Media Player not Working with Buttons

本文关键字:按钮 媒体播放器 Android      更新时间:2023-09-26

我的MediaPlayer不工作。我有9个按钮和9首歌。一首歌代表一个按钮。所有按钮都不工作!对不起,我的英语不好,我来自德国这是我的代码:

import android.media.MediaPlayer;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class MainActivity extends ActionBarActivity {
    private Toolbar toolbar;
    MediaPlayer achieve;
    MediaPlayer iyo;
    MediaPlayer krankelache;
    MediaPlayer mannarzt;
    MediaPlayer missgeburt;
    MediaPlayer mutterfinden;
    MediaPlayer omg;
    MediaPlayer scheisse;
    MediaPlayer twocups;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //MediaPlayer
        this.achieve = MediaPlayer.create(this, R.raw.achieve);
        this.iyo = MediaPlayer.create(this, R.raw.iyo);
        this.krankelache = MediaPlayer.create(this, R.raw.krankelache);
        this.mannarzt = MediaPlayer.create(this, R.raw.mannarzt);
        this.missgeburt = MediaPlayer.create(this, R.raw.missgeburt);
        this.mutterfinden = MediaPlayer.create(this, R.raw.mutterfinden);
        this.twocups = MediaPlayer.create(this, R.raw.twocups);
        this.omg = MediaPlayer.create(this, R.raw.omg);
        this.scheisse = MediaPlayer.create(this, R.raw.scheisse);
        //Toolbar
        toolbar= (Toolbar) findViewById(R.id.app_bar);
        setSupportActionBar(toolbar);
    }
....

感谢

import android.media.MediaPlayer;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
public class MainActivity extends ActionBarActivity {
    private Toolbar toolbar;
    MediaPlayer achieve;
    MediaPlayer iyo;
    MediaPlayer krankelache;
    MediaPlayer mannarzt;
    MediaPlayer missgeburt;
    MediaPlayer mutterfinden;
    MediaPlayer omg;
    MediaPlayer scheisse;
    MediaPlayer twocups;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //MediaPlayer
        this.achieve = MediaPlayer.create(this, R.raw.achieve);
        this.iyo = MediaPlayer.create(this, R.raw.iyo);
        this.krankelache = MediaPlayer.create(this, R.raw.krankelache);
        this.mannarzt = MediaPlayer.create(this, R.raw.mannarzt);
        this.missgeburt = MediaPlayer.create(this, R.raw.missgeburt);
        this.mutterfinden = MediaPlayer.create(this, R.raw.mutterfinden);
        this.twocups = MediaPlayer.create(this, R.raw.twocups);
        this.omg = MediaPlayer.create(this, R.raw.omg);
        this.scheisse = MediaPlayer.create(this, R.raw.scheisse);
        //Toolbar
        toolbar= (Toolbar) findViewById(R.id.app_bar);
        setSupportActionBar(toolbar);
    }
....