Пример #1
0
  public Gyroscope() {
    Activity activity = WeakActivityHolder.get();

    // Get an instance of the SensorManager
    mSensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE);
    mGyroscope = mSensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE);

    isEnabled_ = false;
  }
Пример #2
0
  public synchronized long BackgroundMusicCreateFromFile(String fileName, int[] error) {
    if (fileName.equals("")) {
      error[0] = GAUDIO_CANNOT_OPEN_FILE;
      return 0;
    }

    AssetFileDescriptor fd = null;

    if (fileName.startsWith("/")) {
      File file = new File(fileName);
      if (!file.isFile()) {
        error[0] = GAUDIO_CANNOT_OPEN_FILE;
        return 0;
      }
    } else {
      if (patchFile_ != null) fd = patchFile_.getAssetFileDescriptor(fileName);
      if (fd == null && mainFile_ != null) fd = mainFile_.getAssetFileDescriptor(fileName);
      if (fd == null)
        try {
          fd = WeakActivityHolder.get().getAssets().openFd("assets/" + fileName);
        } catch (IOException e) {
        }

      if (fd == null) {
        error[0] = GAUDIO_CANNOT_OPEN_FILE;
        return 0;
      }
    }

    MediaPlayer player = new MediaPlayer();

    int duration = 0;

    try {
      if (fd != null) {
        player.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
        fd.close();
      } else {
        player.setDataSource(fileName);
      }
      player.prepare();
      duration = player.getDuration();
      player.release();
      player = null;
    } catch (Exception e) {
      error[0] = GAUDIO_UNRECOGNIZED_FORMAT;
      return 0;
    }

    long gid = nextgid();

    sounds_.put(gid, new Sound(fileName, duration));

    return gid;
  }
Пример #3
0
  public synchronized long BackgroundMusicPlay(long backgroundMusic, boolean paused, long data) {
    Sound sound2 = sounds_.get(backgroundMusic);

    if (sound2 == null) return 0;

    String fileName = sound2.fileName;

    AssetFileDescriptor fd = null;

    if (fileName.startsWith("/")) {
      File file = new File(fileName);
      if (!file.isFile()) return 0;
    } else {
      if (patchFile_ != null) fd = patchFile_.getAssetFileDescriptor(fileName);
      if (fd == null && mainFile_ != null) fd = mainFile_.getAssetFileDescriptor(fileName);
      if (fd == null)
        try {
          fd = WeakActivityHolder.get().getAssets().openFd("assets/" + fileName);
        } catch (IOException e) {
        }

      if (fd == null) return 0;
    }

    MediaPlayer player = new MediaPlayer();

    try {
      if (fd != null) {
        player.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
        fd.close();
      } else {
        player.setDataSource(fileName);
      }
      player.prepare();
    } catch (Exception e) {
      return 0;
    }

    long gid = nextgid();

    player.setOnCompletionListener(new OnCompletionListener(this, gid));

    Channel channel = new Channel(gid, player, sound2, data);

    sound2.channels.add(channel);

    channels_.put(gid, channel);

    channel.paused = paused;
    if (!paused) channel.player.start();

    return gid;
  }
Пример #4
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mGLView = new GiderosGLSurfaceView(this);
    setContentView(mGLView);
    mGLView.setOnTouchListener(this);

    WeakActivityHolder.set(this);

    GiderosApplication.onCreate(externalClasses);
  }