Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```java
- public class MainActivity extends Activity {
- ImageView maru_button,batsu_button,qbutton,rbutton;
- private SoundPool mSoundPool;
- private int maru_SoundId,batsu_SoundId,q_SoundId,r_SoundId;
- InterstitialAd mInterstitialAd;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- maru_button = (ImageView) findViewById(R.id.maru);
- batsu_button = (ImageView) findViewById(R.id.batsu);
- qbutton = (ImageView) findViewById(R.id.qbutton);
- rbutton = (ImageView) findViewById(R.id.rbutton);
- maru_button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- //音声
- if (mInterstitialAd.isLoaded()) {
- mInterstitialAd.show();
- } else {
- mSoundPool.play(maru_SoundId, 1.0F, 1.0F, 0, 0, 1.0F);
- }
- }
- });
- batsu_button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- mSoundPool.play(batsu_SoundId, 1.0F, 1.0F, 0, 0, 1.0F);
- }
- });
- qbutton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- mSoundPool.play(q_SoundId, 1.0F, 1.0F, 0, 0, 1.0F);
- }
- });
- rbutton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- mSoundPool.play(r_SoundId, 1.0F, 1.0F, 0, 0, 1.0F);
- }
- });
- AdView mAdView = (AdView) findViewById(R.id.adView);
- AdRequest adRequest = new AdRequest.Builder().build();
- mAdView.loadAd(adRequest);
- mInterstitialAd = new InterstitialAd(this);
- mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
- mInterstitialAd.setAdListener(new AdListener() {
- @Override
- public void onAdClosed() {
- requestNewInterstitial();
- }
- });
- requestNewInterstitial();
- }
- private void requestNewInterstitial() {
- AdRequest adRequest = new AdRequest.Builder()
- .addTestDevice("SEE_YOUR_LOGCAT_TO_GET_YOUR_DEVICE_ID")
- .build();
- mInterstitialAd.loadAd(adRequest);
- }
- @Override
- protected void onResume() {
- super.onResume();
- //音声
- mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
- maru_SoundId = mSoundPool.load(getApplicationContext(), R.raw.correct, 0);
- batsu_SoundId = mSoundPool.load(getApplicationContext(),R.raw.wrong,0);
- q_SoundId = mSoundPool.load(getApplicationContext(),R.raw.question,0);
- r_SoundId = mSoundPool.load(getApplicationContext(),R.raw.result,0);
- }
- @Override
- protected void onPause() {
- super.onPause();
- // リリース
- mSoundPool.release();
- }
- }
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement