如何在android中播放.wma文件

时间:2016-02-10 14:26:56

标签: android

我正在尝试在我的Android应用程序中播放.wma音频文件。但该应用程序在播放wma文件时提供NULL POINTER EXCEPTION,但对mp3文件完全正常 代码:

public class Sounds extends Activity{
    private MediaPlayer mp;
    private Button bbb;
    boolean flag = true;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sounds);
        setVolumeControlStream(AudioManager.STREAM_MUSIC);
        bbb = (Button)findViewById(R.id.buttonSong);
        bbb.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub  
                if(mp == null)
            mp=MediaPlayer.create(getApplicationContext(),R.raw.testing);
            if(mp.isPlaying())
            {
                mp.pause();
                bbb.setText("Pause");
            }
            else
            {
                mp.start();
                bbb.setText("Start");
            }
            }
            });
    }
    }

Log Cat:

02-10 21:13:39.912: E/AndroidRuntime(19350): FATAL EXCEPTION: main
02-10 21:13:39.912: E/AndroidRuntime(19350): java.lang.NullPointerException
02-10 21:13:39.912: E/AndroidRuntime(19350):    at com.example.audiotest.Sounds$1.onClick(Sounds.java:29)
02-10 21:13:39.912: E/AndroidRuntime(19350):    at android.view.View.performClick(View.java:4147)
02-10 21:13:39.912: E/AndroidRuntime(19350):    at android.view.View$PerformClick.run(View.java:17161)
02-10 21:13:39.912: E/AndroidRuntime(19350):    at android.os.Handler.handleCallback(Handler.java:615)
02-10 21:13:39.912: E/AndroidRuntime(19350):    at android.os.Handler.dispatchMessage(Handler.java:92)
02-10 21:13:39.912: E/AndroidRuntime(19350):    at android.os.Looper.loop(Looper.java:213)
02-10 21:13:39.912: E/AndroidRuntime(19350):    at android.app.ActivityThread.main(ActivityThread.java:4787)
02-10 21:13:39.912: E/AndroidRuntime(19350):    at java.lang.reflect.Method.invokeNative(Native Method)
02-10 21:13:39.912: E/AndroidRuntime(19350):    at java.lang.reflect.Method.invoke(Method.java:511)
02-10 21:13:39.912: E/AndroidRuntime(19350):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
02-10 21:13:39.912: E/AndroidRuntime(19350):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
02-10 21:13:39.912: E/AndroidRuntime(19350):    at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案