public void onClickYellowHat(View view) {
   if (mpCheer.isPlaying() || mpCheer.isLooping()) {
     mpCheer.stop();
     mpCheer = MediaPlayer.create(this, R.raw.cheering);
   }
   mpAww.start();
 }
 public void onClickBlueHat(View view) {
   if (mpAww.isPlaying() || mpAww.isLooping()) {
     mpAww.stop();
     mpAww = MediaPlayer.create(this, R.raw.aww);
   }
   mpCheer.start();
 }
Exemple #3
0
 public boolean isLooping() {
   synchronized (this.lock) {
     if (this.player != null && this.started) {
       return player.isLooping();
     }
     return false;
   }
 }
 /** Terminates any audio playback which is in progress. */
 private void terminateAudioPlayback() {
   try {
     if (lMediaPlayer != null) {
       if (lMediaPlayer.isPlaying() || lMediaPlayer.isLooping()) {
         lMediaPlayer.stop();
       }
       lMediaPlayer.release();
       lMediaPlayer = null;
     }
   } catch (final Exception e) {
     // Media player failed.
     Log.e(TAG, "InteractionClient: MediaPlayer error", e);
   } finally {
     setAudioPlaybackState(NOT_BUSY);
   }
 }
Exemple #5
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_home_screen);

    // Loading Sound
    mp = MediaPlayer.create(this, R.raw.sound);
    mp.start();
    if (!mp.isLooping()) ;
    mp.setLooping(true);
    Button musicTitle = (Button) this.findViewById(R.id.button2);
    musicTitle.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            if (!mp.isPlaying()) {
              mp.start();
            } else {
              mp.pause();
            }
          }
        });

    // Load the ImageView that will host the animation and
    // set its background to our AnimationDrawable XML resource.
    ImageView img = (ImageView) findViewById(R.id.gif_img);
    img.setBackgroundResource(R.drawable.img_list);

    // Get the background, which has been compiled to an AnimationDrawable object.
    frameAnimation = (AnimationDrawable) img.getBackground();

    // Start the animation (looped playback by default).
    frameAnimation.start();
  }
Exemple #6
0
 @Override
 public boolean isLooping() {
   return mediaPlayer.isLooping();
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_friend_in_game);
    toolbar = (Toolbar) findViewById(R.id.tool_bar);
    setSupportActionBar(toolbar);

    // start media
    if (mediaPlayer == null) {
      mediaPlayer = MediaPlayer.create(this, R.raw.carefree);
      mediaPlayer.isLooping();
      mediaPlayer.start();
    }

    levelNumberString = getIntent().getExtras().getString("LevelNumber");
    setTitle(levelNumberString);
    String numberString = levelNumberString.substring(levelNumberString.length() - 1);
    levelNumberInt = Integer.parseInt(numberString);

    /** setup the map */
    boardHoles();

    int blocksize = blockSize(levelWidth);

    LinearLayout llHorizontal = (LinearLayout) findViewById(R.id.linearlayout_main);
    llHorizontal.setBackgroundColor(R.color.bgBlue);
    for (int c = 1; c < levelWidth + 1; c++) {
      LinearLayout llVertical = new LinearLayout(this);
      llVertical.setOrientation(LinearLayout.VERTICAL);

      // add 5 blocks
      for (int r = 1; r < levelLength + 1; r++) {
        if (!arrayD.contains(r * 10 + c)) {

          ImageView ib = new ImageView(this);
          Bitmap b =
              decodeSampledBitmapFromResource(
                  getResources(), R.drawable.empty_block, blocksize, blocksize);
          BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), b);
          ib.setImageDrawable(bitmapDrawable);

          // set border
          final int sdk = android.os.Build.VERSION.SDK_INT;
          if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            ib.setBackgroundDrawable(getResources().getDrawable(R.drawable.border));
          } else {
            ib.setBackground(getResources().getDrawable(R.drawable.border));
          }
          int id = r * 10 + c;
          ib.setOnClickListener(onClickListener);
          ib.setId(id);
          llVertical.addView(ib);
          blockNumbers++;
        } else {
          ImageView ib = new ImageView(this);
          Bitmap b =
              decodeSampledBitmapFromResource(
                  getResources(), R.drawable.block_black, blocksize, blocksize);
          BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), b);
          ib.setImageDrawable(bitmapDrawable);
          // set border
          final int sdk = android.os.Build.VERSION.SDK_INT;
          if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            ib.setBackgroundDrawable(getResources().getDrawable(R.drawable.border));
          } else {
            ib.setBackground(getResources().getDrawable(R.drawable.border));
          }
          int id = 1000 + r * 10 + c;
          ib.setId(id);
          llVertical.addView(ib);
          blockNumbers++;
        }
      }

      llHorizontal.addView(llVertical);

      // turn
      TextView tv = (TextView) findViewById(R.id.playerAB);
      if (turn == 0) {
        tv.setText("Orange");
        tv.setTextColor(Color.parseColor("#ff9000"));
      }
    }
  }
 public boolean isMusicLooping() {
   return Music.isLooping();
 }
  /**
   * Invokes the Android {@link MediaPlayer} to playback audio if audio playback was requested, and
   * continues to analyze the response. If the response does not contain audio stream or if audio
   * playback was not requested, continues to analyze the response.
   *
   * @param handler {@link Handler}, to interact with app components in the main thread.
   * @param result {@link PostContentResult}, response from the Amazon Lex service.
   * @param client {@link InteractionClient}, reference to this object.
   * @param responseMode {@link ResponseType}, current response type.
   */
  private void processResponseAudioPlayback(
      final Handler handler,
      final PostContentResult result,
      final InteractionClient client,
      final ResponseType responseMode,
      final ResponseType requestType) {
    // Check if response is audio and audio playback is requested.
    if (ResponseType.AUDIO_MPEG.equals(responseMode) && interactionConfig.isEnableAudioPlayback()) {
      this.lMediaPlayer = new MediaPlayer();
      this.lMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
      try {
        setAudioPlaybackState(BUSY);
        File tempAudioFile = File.createTempFile("lex_temp_response", "mp3", context.getFilesDir());
        tempAudioFile.deleteOnExit();
        // Media player listeners.
        lMediaPlayer.setOnErrorListener(
            new MediaPlayer.OnErrorListener() {
              @Override
              public boolean onError(final MediaPlayer mp, final int what, final int extra) {
                if (interactionListener != null) {
                  final Runnable appCallback =
                      new Runnable() {
                        @Override
                        public void run() {
                          audioPlaybackListener.onAudioPlaybackError(
                              new AudioPlaybackException(
                                  String.format(
                                      Locale.US,
                                      "MediaPlayer error: \"what\": %d, \"extra\":%d",
                                      what,
                                      extra)));
                        }
                      };
                  handler.post(appCallback);
                }
                return false;
              }
            });

        lMediaPlayer.setOnPreparedListener(
            new MediaPlayer.OnPreparedListener() {
              @Override
              public void onPrepared(MediaPlayer mp) {
                if (audioPlaybackListener != null) {
                  final Runnable appCallback =
                      new Runnable() {
                        @Override
                        public void run() {
                          audioPlaybackListener.onAudioPlaybackStarted();
                        }
                      };
                  handler.post(appCallback);
                }
                mp.start();
              }
            });

        lMediaPlayer.setOnCompletionListener(
            new MediaPlayer.OnCompletionListener() {
              @Override
              public void onCompletion(MediaPlayer mp) {
                setAudioPlaybackState(NOT_BUSY);
                if (audioPlaybackListener != null) {
                  final Runnable appCallback =
                      new Runnable() {
                        @Override
                        public void run() {
                          audioPlaybackListener.onAudioPlayBackCompleted();
                        }
                      };
                  handler.post(appCallback);
                }
                try {
                  if (lMediaPlayer.isPlaying() || lMediaPlayer.isLooping()) {
                    lMediaPlayer.stop();
                  }
                  lMediaPlayer.release();
                } catch (final Exception e) {
                  Log.e(TAG, "InteractionClient: Error while releasing MediaPlayer", e);
                } finally {
                  lMediaPlayer = null;
                }
              }
            });

        final InputStream audioStream = result.getAudioStream();
        tempAudioFile = File.createTempFile("lex_temp_response", "dat", context.getFilesDir());
        tempAudioFile.deleteOnExit();
        final FileOutputStream audioOut = new FileOutputStream(tempAudioFile);
        final byte buffer[] = new byte[16384];
        int length;
        while ((length = audioStream.read(buffer)) != -1) {
          audioOut.write(buffer, 0, length);
        }
        audioOut.close();
        final FileInputStream audioIn = new FileInputStream(tempAudioFile);
        lMediaPlayer.setDataSource(audioIn.getFD());
        lMediaPlayer.prepare();
        processResponse(handler, result, client, responseMode, requestType);
      } catch (final Exception e) {
        // Playback failed.
        if (audioPlaybackListener != null) {
          final Runnable appCallback =
              new Runnable() {
                @Override
                public void run() {
                  audioPlaybackListener.onAudioPlaybackError(
                      new LexClientException("Audio playback failed", e));
                }
              };
          handler.post(appCallback);
        }
        try {
          if (lMediaPlayer.isPlaying() || lMediaPlayer.isLooping()) {
            lMediaPlayer.stop();
          }
          lMediaPlayer.release();
          lMediaPlayer = null;
        } catch (final Exception exp) {
          Log.e(TAG, "InteractionClient: Error while releasing MediaPlayer", exp);
        }
        processResponse(handler, result, client, responseMode, requestType);
      } finally {
        setAudioPlaybackState(NOT_BUSY);
      }

    } else {
      processResponse(handler, result, client, responseMode, requestType);
    }
  }