「タピア」を使用して音楽を流します。AndroidのAPIを使用します。
◆◇◆◇◆サンプルコード:TAPIAから音楽を流します◆◇◆◇◆
1) ボタンを追加する
サンプルコード「0.ボタンを追加する」を参考に作成します
2) Activityに以下処理を追加する
//音楽再生する
public class _MusicActivity extends TapiaActivity {
TapiaAnimation tapiaAnimation;
private MediaPlayer mPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.eyes_layout);
ImageView tapiaEyes = (ImageView) findViewById(R.id.eyes);
//アニメーションの設定をする
tapiaAnimation = new TapiaAnimation(this,tapiaEyes);
tapiaAnimation.startAnimation(TapiaAnimation.CLEAR,true);
//音量の設定をする (0-10より選択、0は消音)
TapiaAudio.setVolume(this, 5, false);
mPlayer = new MediaPlayer();
// 出力ファイルを指定(任意に設定:Musicフォルダにmp3ファイルを保存する)
String filePath = Environment.getExternalStorageDirectory().toString() + "/Music/music.mp3";
try {
mPlayer.setDataSource(filePath);
mPlayer.prepare();
} catch (IOException e) {
e.printStackTrace();
}
mPlayer.start();
//顔画面長押しで終了する
tapiaEyes.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
mPlayer.release();
finish();
return false;
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
mPlayer.release();
}
@Override
protected void onResume() {
super.onResume();
}
@Override
protected void onPause() {
super.onPause();
}
}