Hi guys,
I'm currently implementing on an android apps for my final year project which helps on current parents on saving some good money and time with this E-Tutor for toddler. Currently I've created a subpage which navigates from Mainpage-> Music page. At which the Music page allows to play some music after hitting various music button, and also having a "Back to Home" button.
First question: - How am I able to implement efficiently that different button tagging to various individual songs instead of creating 8 different classes for 8 different buttons tagging to each song individually? Below is my short codes.
=====MusicActivity Class==========================
button = (Button) findViewById(R.id.btnButton16);
button.setOnClickListener(new OnClickListener()
{
@override
public void onClick(View v)
{
BtnButton16.play(getBaseContext(), R.raw.test);
}
});
}
==============================================
=====BtnButton16 Class==========================
import android.media.MediaPlayer;
import android.content.Context;
public class BtnButton16 {
private static MediaPlayer mp = null;
//private static MediaPlayer mpEffect = null;
public static void play(Context context, int resources)
{
mp = MediaPlayer.create(context, resources);
mp.start();
}
public static void stop(Context context)
{
if (mp != null)
{
mp.stop();
mp.release();
mp = null;
}
}
}
==============================================
Second question: - How am I able to prevent music from playing again(stack or overlapping songs) after hitting the same "Song" button or other button?
Third question: - How am i able to stop music immediately after i hit the "Back to Home" button? It seems like if I implement mp.stop(); command within my "Back to Home" button, it will create error which force the program to close off.
=====BtnButton23 (Back to home)======================
button = (Button) findViewById(R.id.btnButton23);
button.setOnClickListener(new OnClickListener()
{
@override
public void onClick(View arg0)
{
//mp.stop();
Intent intent = new Intent(context, MainContent.class);
startActivity(intent);
}
});
================================================
Need some professional help! Thanks all in advance of assisting and enlightening me on my project work.
I'm currently implementing on an android apps for my final year project which helps on current parents on saving some good money and time with this E-Tutor for toddler. Currently I've created a subpage which navigates from Mainpage-> Music page. At which the Music page allows to play some music after hitting various music button, and also having a "Back to Home" button.
First question: - How am I able to implement efficiently that different button tagging to various individual songs instead of creating 8 different classes for 8 different buttons tagging to each song individually? Below is my short codes.
=====MusicActivity Class==========================
button = (Button) findViewById(R.id.btnButton16);
button.setOnClickListener(new OnClickListener()
{
@override
public void onClick(View v)
{
BtnButton16.play(getBaseContext(), R.raw.test);
}
});
}
==============================================
=====BtnButton16 Class==========================
import android.media.MediaPlayer;
import android.content.Context;
public class BtnButton16 {
private static MediaPlayer mp = null;
//private static MediaPlayer mpEffect = null;
public static void play(Context context, int resources)
{
mp = MediaPlayer.create(context, resources);
mp.start();
}
public static void stop(Context context)
{
if (mp != null)
{
mp.stop();
mp.release();
mp = null;
}
}
}
==============================================
Second question: - How am I able to prevent music from playing again(stack or overlapping songs) after hitting the same "Song" button or other button?
Third question: - How am i able to stop music immediately after i hit the "Back to Home" button? It seems like if I implement mp.stop(); command within my "Back to Home" button, it will create error which force the program to close off.
=====BtnButton23 (Back to home)======================
button = (Button) findViewById(R.id.btnButton23);
button.setOnClickListener(new OnClickListener()
{
@override
public void onClick(View arg0)
{
//mp.stop();
Intent intent = new Intent(context, MainContent.class);
startActivity(intent);
}
});
================================================
Need some professional help! Thanks all in advance of assisting and enlightening me on my project work.