我正在使用Android Studio.I嘗試了我在互聯網上看到的所有代碼,但我的應用程序無法正常工作。我有一個原始文件夾,其中包含我將要使用的音樂,但仍然不知道我的代碼中有什麼錯誤。爲什麼我的音樂無法在Android Studio上播放?
這裏是我的代碼:
package com.example.aloja.babysteps;
import android.app.Activity;
import android.content.Context;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
/**
* Created by Aloja on 3/27/2017.
*/
public class A extends Activity {
Button btnBack3,btnPlay;
ImageView ivApple;
MediaPlayer apple;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.a);
btnBack3 = (Button) findViewById(R.id.btnBack3);
btnPlay =(Button) findViewById(R.id.btnPlay);
ivApple = (ImageView) findViewById(R.id.ivApple);
ivApple.setImageResource(R.drawable.apple);
apple= MediaPlayer.create(this, R.raw.apple);
btnPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
apple.start();
}
});
}
protected void onPause(){
super.onPause();
apple.stop();
apple.release();
}
}
P.S對不起,我的英語水平。希望你明白我想問什麼
請發佈錯誤日誌。 你正在得到什麼錯誤? –
我在這裏沒有看到任何錯誤,因爲我的應用程序正在運行,但我的音樂無法播放。 – callme123