コード例 #1
0
  /**
   * create mediaplayer for music
   *
   * @param pPath the pPath relative to assets
   * @return
   */
  private MediaPlayer createMediaplayer(final String path) {
    MediaPlayer mediaPlayer = new MediaPlayer();

    try {
      if (CocosPlayClient.isEnabled() && !CocosPlayClient.isDemo()) {
        CocosPlayClient.updateAssets(path);
      }
      CocosPlayClient.notifyFileLoaded(path);
      if (path.startsWith("/")) {
        final FileInputStream fis = new FileInputStream(path);
        mediaPlayer.setDataSource(fis.getFD());
        fis.close();
      } else {
        final AssetFileDescriptor assetFileDescritor = this.mContext.getAssets().openFd(path);
        mediaPlayer.setDataSource(
            assetFileDescritor.getFileDescriptor(),
            assetFileDescritor.getStartOffset(),
            assetFileDescritor.getLength());
      }

      mediaPlayer.prepare();

      mediaPlayer.setVolume(this.mLeftVolume, this.mRightVolume);
    } catch (final Exception e) {
      mediaPlayer = null;
      Log.e(Cocos2dxMusic.TAG, "error: " + e.getMessage(), e);
    }

    return mediaPlayer;
  }
コード例 #2
0
  @Override
  protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    CocosPlayClient.init(this, false);
    onLoadNativeLibraries();
    SDKBox.init(this);

    sContext = this;
    this.mHandler = new Cocos2dxHandler(this);

    Cocos2dxHelper.init(this);

    this.mGLContextAttrs = getGLContextAttrs();
    this.init();

    if (mVideoHelper == null) {
      mVideoHelper = new Cocos2dxVideoHelper(this, mFrameLayout);
    }

    if (mWebViewHelper == null) {
      mWebViewHelper = new Cocos2dxWebViewHelper(mFrameLayout);
    }
  }