Android Media Player无法使用按钮

时间:2015-03-04 17:40:10

标签: javascript android media

我的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);
    }
....

由于

1 个答案:

答案 0 :(得分:0)



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);
    }
....