コード例 #1
0
 @Override
 public void execute() {
   if (sound != null && sprite.getSoundList().contains(sound)) {
     if (!NativeAppActivity.isRunning() && sound.getAbsolutePath() != null) {
       SoundManager.getInstance().playSoundFile(sound.getAbsolutePath());
     } else {
       SoundManager.getInstance().playSoundFile("sounds/" + sound.getSoundFileName());
     }
   }
 }
コード例 #2
0
 private ArrayAdapter<?> createSoundAdapter(Context context) {
   ArrayAdapter<SoundInfo> arrayAdapter =
       new ArrayAdapter<SoundInfo>(context, android.R.layout.simple_spinner_item);
   arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
   SoundInfo dummySoundInfo = new SoundInfo();
   dummySoundInfo.setTitle(context.getString(R.string.broadcast_nothing_selected));
   arrayAdapter.add(dummySoundInfo);
   for (SoundInfo soundInfo : sprite.getSoundList()) {
     arrayAdapter.add(soundInfo);
   }
   return arrayAdapter;
 }
コード例 #3
0
ファイル: StageDialogTest.java プロジェクト: crayons/Catroid
  public void testRestartProjectWithSound() {
    String projectName = UiTestUtils.PROJECTNAME1;
    // creating sprites for project:
    Sprite firstSprite = new Sprite("sprite1");
    Script startScript = new StartScript(firstSprite);

    PlaySoundBrick playSoundBrick = new PlaySoundBrick(firstSprite);

    startScript.addBrick(playSoundBrick);

    firstSprite.addScript(startScript);

    ArrayList<Sprite> spriteList = new ArrayList<Sprite>();
    spriteList.add(firstSprite);
    Project project = UiTestUtils.createProject(projectName, spriteList, getActivity());

    File soundFile =
        UiTestUtils.saveFileToProject(
            projectName,
            "soundfile.mp3",
            at.tugraz.ist.catroid.uitest.R.raw.longsound,
            getInstrumentation().getContext(),
            UiTestUtils.FileTypes.SOUND);

    SoundInfo soundInfo = new SoundInfo();
    soundInfo.setSoundFileName(soundFile.getName());
    soundInfo.setTitle(soundFile.getName());
    playSoundBrick.setSoundInfo(soundInfo);

    firstSprite.getSoundList().add(soundInfo);

    storageHandler.saveProject(project);

    MediaPlayer mediaPlayer = SoundManager.getInstance().getMediaPlayer();
    UiTestUtils.clickOnActionBar(solo, R.id.menu_start);
    solo.waitForActivity(StageActivity.class.getSimpleName());
    solo.sleep(1000);
    assertTrue("Sound not playing.", mediaPlayer.isPlaying());
    int positionBeforeRestart = mediaPlayer.getCurrentPosition();
    solo.goBack();
    solo.sleep(500);
    assertFalse("Sound playing but should be paused.", mediaPlayer.isPlaying());
    solo.clickOnButton(getActivity().getString(R.string.restart_current_project));
    solo.sleep(300);
    @SuppressWarnings("unchecked")
    ArrayList<MediaPlayer> mediaPlayerArrayList =
        (ArrayList<MediaPlayer>)
            UiTestUtils.getPrivateField("mediaPlayers", SoundManager.getInstance());
    int positionAfterRestart = mediaPlayerArrayList.get(0).getCurrentPosition();
    assertTrue("Sound not playing after stage restart.", mediaPlayerArrayList.get(0).isPlaying());
    assertTrue("Sound did not play from start!", positionBeforeRestart > positionAfterRestart);
  }