Java Code Examples for io.vov.vitamio.utils.Log

The following examples show how to use io.vov.vitamio.utils.Log. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: MyHearts   Source File: MediaPlayer.java    License: Apache License 2.0 6 votes vote down vote up
private void updateSub(int subType, byte[] bytes, String encoding, int width, int height) {
  if (mEventHandler != null) {
    Message m = mEventHandler.obtainMessage(MEDIA_TIMED_TEXT, width, height);
    Bundle b = m.getData();
    if (subType == SUBTITLE_TEXT) {
      b.putInt(MEDIA_SUBTITLE_TYPE, SUBTITLE_TEXT);
      if (encoding == null) {
        b.putString(MEDIA_SUBTITLE_STRING, new String(bytes));
      } else {
        try {
          b.putString(MEDIA_SUBTITLE_STRING, new String(bytes, encoding.trim()));
        } catch (UnsupportedEncodingException e) {
          Log.e("updateSub", e);
          b.putString(MEDIA_SUBTITLE_STRING, new String(bytes));
        }
      }
    } else if (subType == SUBTITLE_BITMAP) {
      b.putInt(MEDIA_SUBTITLE_TYPE, SUBTITLE_BITMAP);
      b.putByteArray(MEDIA_SUBTITLE_BYTES, bytes);
    }
    mEventHandler.sendMessage(m);
  }
}
 
Example 2
Source Project: MyHearts   Source File: MediaScanner.java    License: Apache License 2.0 6 votes vote down vote up
public Uri doScanFile(String path, long lastModified, long fileSize, boolean scanAlways) {
  Uri result = null;
  try {
    FileCacheEntry entry = beginFile(path, lastModified, fileSize);
    if (entry != null && (entry.mLastModifiedChanged || scanAlways)) {
      if (processFile(path, null)) {
        result = endFile(entry);
      } else {
        if (mCaseInsensitivePaths)
          mFileCache.remove(path.toLowerCase());
        else
          mFileCache.remove(path);
      }
    }
  } catch (RemoteException e) {
    Log.e("RemoteException in MediaScanner.scanFile()", e);
  }
  return result;
}
 
Example 3
Source Project: MyHearts   Source File: MediaController.java    License: Apache License 2.0 6 votes vote down vote up
public void hide() {
    if (mAnchor == null)
        return;

    if (mShowing) {
        try {
            mHandler.removeMessages(SHOW_PROGRESS);
            if (mFromXml)
                setVisibility(View.GONE);
            else
                mWindow.dismiss();
        } catch (IllegalArgumentException ex) {
            Log.d("MediaController already removed");
        }
        mShowing = false;
        if (mHiddenListener != null)
            mHiddenListener.onHidden();
    }
}
 
Example 4
Source Project: NetEasyNews   Source File: VideoView.java    License: GNU General Public License v3.0 6 votes vote down vote up
public boolean onError(MediaPlayer mp, int framework_err, int impl_err) {
  Log.d("Error: %d, %d", framework_err, impl_err);
  mCurrentState = STATE_ERROR;
  mTargetState = STATE_ERROR;
  if (mMediaController != null)
    mMediaController.hide();

  if (mOnErrorListener != null) {
    if (mOnErrorListener.onError(mMediaPlayer, framework_err, impl_err))
      return true;
  }

  if (getWindowToken() != null) {
    int message = framework_err == MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK ? getResources().getIdentifier("VideoView_error_text_invalid_progressive_playback", "string", mContext.getPackageName()): getResources().getIdentifier("VideoView_error_text_unknown", "string", mContext.getPackageName());

    new AlertDialog.Builder(mContext).setTitle(getResources().getIdentifier("VideoView_error_title", "string", mContext.getPackageName())).setMessage(message).setPositiveButton(getResources().getIdentifier("VideoView_error_button", "string", mContext.getPackageName()), new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int whichButton) {
        if (mOnCompletionListener != null)
          mOnCompletionListener.onCompletion(mMediaPlayer);
      }
    }).setCancelable(false).show();
  }
  return true;
}
 
Example 5
Source Project: MyHearts   Source File: VideoView.java    License: Apache License 2.0 6 votes vote down vote up
public boolean onError(MediaPlayer mp, int framework_err, int impl_err) {
  Log.d("Error: %d, %d", framework_err, impl_err);
  mCurrentState = STATE_ERROR;
  mTargetState = STATE_ERROR;
  if (mMediaController != null)
    mMediaController.hide();
  if (mOnErrorListener != null) {
    if (mOnErrorListener.onError(mMediaPlayer, framework_err, impl_err))
      return true;
  }

  if (getWindowToken() != null) {
    int message = framework_err == MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK ? getResources().getIdentifier("VideoView_error_text_invalid_progressive_playback", "string", mContext.getPackageName()): getResources().getIdentifier("VideoView_error_text_unknown", "string", mContext.getPackageName());

    new AlertDialog.Builder(mContext).setTitle(getResources().getIdentifier("VideoView_error_title", "string", mContext.getPackageName())).setMessage(message).setPositiveButton(getResources().getIdentifier("VideoView_error_button", "string", mContext.getPackageName()), new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int whichButton) {
        if (mOnCompletionListener != null)
          mOnCompletionListener.onCompletion(mMediaPlayer);
      }
    }).setCancelable(false).show();
  }
  return true;
}
 
Example 6
Source Project: HPlayer   Source File: MediaScanner.java    License: Apache License 2.0 6 votes vote down vote up
public Uri doScanFile(String path, long lastModified, long fileSize, boolean scanAlways) {
  Uri result = null;
  try {
    FileCacheEntry entry = beginFile(path, lastModified, fileSize);
    if (entry != null && (entry.mLastModifiedChanged || scanAlways)) {
      if (processFile(path, null)) {
        result = endFile(entry);
      } else {
        if (mCaseInsensitivePaths)
          mFileCache.remove(path.toLowerCase());
        else
          mFileCache.remove(path);
      }
    }
  } catch (RemoteException e) {
    Log.e("RemoteException in MediaScanner.scanFile()", e);
  }
  return result;
}
 
Example 7
Source Project: HPlayer   Source File: MediaController.java    License: Apache License 2.0 6 votes vote down vote up
public void hide() {
  if (mAnchor == null)
    return;

  if (mShowing) {
    try {
      mHandler.removeMessages(SHOW_PROGRESS);
      if (mFromXml)
        setVisibility(View.GONE);
      else
        mWindow.dismiss();
    } catch (IllegalArgumentException ex) {
      Log.d("MediaController already removed");
    }
    mShowing = false;
    if (mHiddenListener != null)
      mHiddenListener.onHidden();
  }
}
 
Example 8
Source Project: HPlayer   Source File: VideoView.java    License: Apache License 2.0 6 votes vote down vote up
public boolean onError(MediaPlayer mp, int framework_err, int impl_err) {
  Log.d("Error: %d, %d", framework_err, impl_err);
  mCurrentState = STATE_ERROR;
  mTargetState = STATE_ERROR;
  if (mMediaController != null)
    mMediaController.hide();

  if (mOnErrorListener != null) {
    if (mOnErrorListener.onError(mMediaPlayer, framework_err, impl_err))
      return true;
  }

  if (getWindowToken() != null) {
    int message = framework_err == MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK ? getResources().getIdentifier("VideoView_error_text_invalid_progressive_playback", "string", mContext.getPackageName()): getResources().getIdentifier("VideoView_error_text_unknown", "string", mContext.getPackageName());

    new AlertDialog.Builder(mContext).setTitle(getResources().getIdentifier("VideoView_error_title", "string", mContext.getPackageName())).setMessage(message).setPositiveButton(getResources().getIdentifier("VideoView_error_button", "string", mContext.getPackageName()), new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int whichButton) {
        if (mOnCompletionListener != null)
          mOnCompletionListener.onCompletion(mMediaPlayer);
      }
    }).setCancelable(false).show();
  }
  return true;
}
 
Example 9
Source Project: video-player   Source File: MediaPlayer.java    License: MIT License 6 votes vote down vote up
private void updateSub(int subType, byte[] bytes, String encoding, int width, int height) {
  if (mEventHandler != null) {
    Message m = mEventHandler.obtainMessage(MEDIA_TIMED_TEXT, width, height);
    Bundle b = m.getData();
    if (subType == SUBTITLE_TEXT) {
      b.putInt(MEDIA_SUBTITLE_TYPE, SUBTITLE_TEXT);
      if (encoding == null) {
        b.putString(MEDIA_SUBTITLE_STRING, new String(bytes));
      } else {
        try {
          b.putString(MEDIA_SUBTITLE_STRING, new String(bytes, encoding.trim()));
        } catch (UnsupportedEncodingException e) {
          Log.e("updateSub", e);
          b.putString(MEDIA_SUBTITLE_STRING, new String(bytes));
        }
      }
    } else if (subType == SUBTITLE_BITMAP) {
      b.putInt(MEDIA_SUBTITLE_TYPE, SUBTITLE_BITMAP);
      b.putByteArray(MEDIA_SUBTITLE_BYTES, bytes);
    }
    mEventHandler.sendMessage(m);
  }
}
 
Example 10
Source Project: video-player   Source File: MediaPlayer.java    License: MIT License 6 votes vote down vote up
@SuppressLint("NewApi")
  
private int audioTrackInit(int sampleRateInHz, int channels) {
 //  this.sampleRateInHz=sampleRateInHz;
 //  this.channels=channels;
 //   return 0;
	
 audioTrackRelease();
    int channelConfig = channels >= 2 ? AudioFormat.CHANNEL_OUT_STEREO : AudioFormat.CHANNEL_OUT_MONO;
    try {
      mAudioTrackBufferSize = AudioTrack.getMinBufferSize(sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT);
      mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT, mAudioTrackBufferSize, AudioTrack.MODE_STREAM);
    } catch (Exception e) {
      mAudioTrackBufferSize = 0;
      Log.e("audioTrackInit", e);
    }
    return mAudioTrackBufferSize;
  }
 
Example 11
Source Project: video-player   Source File: MediaScanner.java    License: MIT License 6 votes vote down vote up
public Uri doScanFile(String path, long lastModified, long fileSize, boolean scanAlways) {
  Uri result = null;
  try {
    FileCacheEntry entry = beginFile(path, lastModified, fileSize);
    if (entry != null && (entry.mLastModifiedChanged || scanAlways)) {
      if (processFile(path, null)) {
        result = endFile(entry);
      } else {
        if (mCaseInsensitivePaths)
          mFileCache.remove(path.toLowerCase());
        else
          mFileCache.remove(path);
      }
    }
  } catch (RemoteException e) {
    Log.e("RemoteException in MediaScanner.scanFile()", e);
  }
  return result;
}
 
Example 12
Source Project: video-player   Source File: MediaController.java    License: MIT License 6 votes vote down vote up
public void hide() {
  if (mAnchor == null)
    return;

  if (mShowing) {
    try {
      mHandler.removeMessages(SHOW_PROGRESS);
      if (mFromXml)
        setVisibility(View.GONE);
      else
        mWindow.dismiss();
    } catch (IllegalArgumentException ex) {
      Log.d("MediaController already removed");
    }
    mShowing = false;
    if (mHiddenListener != null)
      mHiddenListener.onHidden();
  }
}
 
Example 13
Source Project: video-player   Source File: VideoView.java    License: MIT License 6 votes vote down vote up
public boolean onError(MediaPlayer mp, int framework_err, int impl_err) {
  Log.d("Error: %d, %d", framework_err, impl_err);
  mCurrentState = STATE_ERROR;
  mTargetState = STATE_ERROR;
  if (mMediaController != null)
    mMediaController.hide();

  if (mOnErrorListener != null) {
    if (mOnErrorListener.onError(mMediaPlayer, framework_err, impl_err))
      return true;
  }

  if (getWindowToken() != null) {
    int message = framework_err == MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK ? getResources().getIdentifier("VideoView_error_text_invalid_progressive_playback", "string", mContext.getPackageName()): getResources().getIdentifier("VideoView_error_text_unknown", "string", mContext.getPackageName());

    new AlertDialog.Builder(mContext).setTitle(getResources().getIdentifier("VideoView_error_title", "string", mContext.getPackageName())).setMessage(message).setPositiveButton(getResources().getIdentifier("VideoView_error_button", "string", mContext.getPackageName()), new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog, int whichButton) {
        if (mOnCompletionListener != null)
          mOnCompletionListener.onCompletion(mMediaPlayer);
      }
    }).setCancelable(false).show();
  }
  return true;
}
 
Example 14
Source Project: NetEasyNews   Source File: MediaPlayer.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void updateSub(int subType, byte[] bytes, String encoding, int width, int height) {
  if (mEventHandler != null) {
    Message m = mEventHandler.obtainMessage(MEDIA_TIMED_TEXT, width, height);
    Bundle b = m.getData();
    if (subType == SUBTITLE_TEXT) {
      b.putInt(MEDIA_SUBTITLE_TYPE, SUBTITLE_TEXT);
      if (encoding == null) {
        b.putString(MEDIA_SUBTITLE_STRING, new String(bytes));
      } else {
        try {
          b.putString(MEDIA_SUBTITLE_STRING, new String(bytes, encoding.trim()));
        } catch (UnsupportedEncodingException e) {
          Log.e("updateSub", e);
          b.putString(MEDIA_SUBTITLE_STRING, new String(bytes));
        }
      }
    } else if (subType == SUBTITLE_BITMAP) {
      b.putInt(MEDIA_SUBTITLE_TYPE, SUBTITLE_BITMAP);
      b.putByteArray(MEDIA_SUBTITLE_BYTES, bytes);
    }
    mEventHandler.sendMessage(m);
  }
}
 
Example 15
Source Project: NetEasyNews   Source File: MediaScanner.java    License: GNU General Public License v3.0 6 votes vote down vote up
public Uri doScanFile(String path, long lastModified, long fileSize, boolean scanAlways) {
  Uri result = null;
  try {
    FileCacheEntry entry = beginFile(path, lastModified, fileSize);
    if (entry != null && (entry.mLastModifiedChanged || scanAlways)) {
      if (processFile(path, null)) {
        result = endFile(entry);
      } else {
        if (mCaseInsensitivePaths)
          mFileCache.remove(path.toLowerCase());
        else
          mFileCache.remove(path);
      }
    }
  } catch (RemoteException e) {
    Log.e("RemoteException in MediaScanner.scanFile()", e);
  }
  return result;
}
 
Example 16
Source Project: MyHearts   Source File: MediaPlayer.java    License: Apache License 2.0 5 votes vote down vote up
private static void postEventFromNative(Object mediaplayer_ref, int what, int arg1, int arg2, Object obj) {
  MediaPlayer mp = (MediaPlayer) (mediaplayer_ref);
  if (mp == null)
    return;

  try {
      //synchronized (mp.mEventHandler) {
      if (mp.mEventHandler != null) {
        Message m = mp.mEventHandler.obtainMessage(what, arg1, arg2, obj);
        mp.mEventHandler.sendMessage(m);
      }
  } catch (Exception e) {
      Log.e("exception: " + e);
  }
}
 
Example 17
Source Project: MyHearts   Source File: MediaPlayer.java    License: Apache License 2.0 5 votes vote down vote up
private void closeFD() {
  if (mFD != null) {
    try {
      mFD.close();
    } catch (IOException e) {
      Log.e("closeFD", e);
    }
    mFD = null;
  }
}
 
Example 18
Source Project: MyHearts   Source File: MediaPlayer.java    License: Apache License 2.0 5 votes vote down vote up
public int audioTrackInit() {
//	  Log.e("  ffff mediaplayer audiotrackinit start .  sampleRateInHz:=" + sampleRateInHz + " channels:=" + channels );
	    audioTrackRelease();
	    int channelConfig = channels >= 2 ? AudioFormat.CHANNEL_OUT_STEREO : AudioFormat.CHANNEL_OUT_MONO;
	    try {
	      mAudioTrackBufferSize = AudioTrack.getMinBufferSize(sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT);
	      mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT, mAudioTrackBufferSize, AudioTrack.MODE_STREAM);
	    } catch (Exception e) {
	      mAudioTrackBufferSize = 0;
	      Log.e("audioTrackInit", e);
	    }
	    return mAudioTrackBufferSize;
	  }
 
Example 19
Source Project: MyHearts   Source File: MediaPlayer.java    License: Apache License 2.0 5 votes vote down vote up
private void surfaceRender() {
  synchronized (this) {
    if (mLocalSurface == null || !mLocalSurface.isValid() || mBitmap == null || mByteBuffer == null)
      return;

    try {
      Canvas c = mLocalSurface.lockCanvas(null);
      mBitmap.copyPixelsFromBuffer(mByteBuffer);
      c.drawBitmap(mBitmap, 0, 0, null);
      mLocalSurface.unlockCanvasAndPost(c);
    } catch (Exception e) {
      Log.e("surfaceRender", e);
    }
  }
}
 
Example 20
Source Project: MyHearts   Source File: MediaScanner.java    License: Apache License 2.0 5 votes vote down vote up
public Uri scanSingleFile(String path, String mimeType) {
  try {
    prescan(path);
    File file = new File(path);
    long lastModifiedSeconds = file.lastModified() / 1000;

    return mClient.doScanFile(path, lastModifiedSeconds, file.length(), true);
  } catch (RemoteException e) {
    Log.e("RemoteException in MediaScanner.scanFile()", e);
    return null;
  }
}
 
Example 21
Source Project: MyHearts   Source File: MediaScanner.java    License: Apache License 2.0 5 votes vote down vote up
public void handleStringTag(String name, byte[] valueBytes, String valueEncoding) {
  String value;
  try {
    value = new String(valueBytes, valueEncoding);
  } catch (Exception e) {
    Log.e("handleStringTag", e);
    value = new String(valueBytes);
  }
  Log.i("%s : %s", name, value);

  if (name.equalsIgnoreCase("title")) {
    mTitle = value;
  } else if (name.equalsIgnoreCase("artist")) {
    mArtist = value.trim();
  } else if (name.equalsIgnoreCase("albumartist")) {
    if (TextUtils.isEmpty(mArtist))
      mArtist = value.trim();
  } else if (name.equalsIgnoreCase("album")) {
    mAlbum = value.trim();
  } else if (name.equalsIgnoreCase("language")) {
    mLanguage = value.trim();
  } else if (name.equalsIgnoreCase("duration")) {
    mDuration = parseSubstring(value, 0, 0);
  } else if (name.equalsIgnoreCase("width")) {
    mWidth = parseSubstring(value, 0, 0);
  } else if (name.equalsIgnoreCase("height")) {
    mHeight = parseSubstring(value, 0, 0);
  }
}
 
Example 22
Source Project: MyHearts   Source File: VideoView.java    License: Apache License 2.0 5 votes vote down vote up
public void onCompletion(MediaPlayer mp) {
  Log.d("onCompletion");
  mCurrentState = STATE_PLAYBACK_COMPLETED;
  mTargetState = STATE_PLAYBACK_COMPLETED;
  if (mMediaController != null)
    mMediaController.hide();
  if (mOnCompletionListener != null)
    mOnCompletionListener.onCompletion(mMediaPlayer);
}
 
Example 23
Source Project: MyHearts   Source File: VideoView.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
  Log.d("onInfo: (%d, %d)", what, extra);
	
  	if(MediaPlayer.MEDIA_INFO_UNKNOW_TYPE == what){
		Log.e(" VITAMIO--TYPE_CHECK  stype  not include  onInfo mediaplayer unknow type ");
	} 
	
	if(MediaPlayer.MEDIA_INFO_FILE_OPEN_OK == what){
		long buffersize=mMediaPlayer.audioTrackInit(); 
		mMediaPlayer.audioInitedOk(buffersize);
	}

  Log.d("onInfo: (%d, %d)", what, extra);

  if (mOnInfoListener != null) {
    mOnInfoListener.onInfo(mp, what, extra);
  } else if (mMediaPlayer != null) {
    if (what == MediaPlayer.MEDIA_INFO_BUFFERING_START) {
      mMediaPlayer.pause();
      if (mMediaBufferingIndicator != null)
        mMediaBufferingIndicator.setVisibility(View.VISIBLE);
    } else if (what == MediaPlayer.MEDIA_INFO_BUFFERING_END) {
      mMediaPlayer.start();
      if (mMediaBufferingIndicator != null)
        mMediaBufferingIndicator.setVisibility(View.GONE);
    }
  }
  return true;
}
 
Example 24
Source Project: MyHearts   Source File: VideoView.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Set the display options
 *
 * @param layout      <ul>
 *                    <li>{@link #VIDEO_LAYOUT_ORIGIN}
 *                    <li>{@link #VIDEO_LAYOUT_SCALE}
 *                    <li>{@link #VIDEO_LAYOUT_STRETCH}
 *                    <li>{@link #VIDEO_LAYOUT_FIT_PARENT}
 *                    <li>{@link #VIDEO_LAYOUT_ZOOM}
 *                    </ul>
 * @param aspectRatio video aspect ratio, will audo detect if 0.
 */
public void setVideoLayout(int layout, float aspectRatio) {
	LayoutParams lp = getLayoutParams();
	Pair<Integer, Integer> res = ScreenResolution.getResolution(mContext);
	int windowWidth = res.first.intValue(), windowHeight = res.second.intValue();
	float windowRatio = windowWidth / (float) windowHeight;
	float videoRatio = aspectRatio <= 0.01f ? mVideoAspectRatio : aspectRatio;
	mSurfaceHeight = mVideoHeight;
	mSurfaceWidth = mVideoWidth;
	if (VIDEO_LAYOUT_ORIGIN == layout && mSurfaceWidth < windowWidth && mSurfaceHeight < windowHeight) {
		lp.width = (int) (mSurfaceHeight * videoRatio);
		lp.height = mSurfaceHeight;
	} else if (layout == VIDEO_LAYOUT_ZOOM) {
		lp.width = windowRatio > videoRatio ? windowWidth : (int) (videoRatio * windowHeight);
		lp.height = windowRatio < videoRatio ? windowHeight : (int) (windowWidth / videoRatio);
	} else if (layout == VIDEO_LAYOUT_FIT_PARENT) {
		ViewGroup parent = (ViewGroup) getParent();
		float parentRatio = ((float) parent.getWidth()) / ((float) parent.getHeight());
		lp.width = (parentRatio < videoRatio) ? parent.getWidth() : Math.round(((float) parent.getHeight()) * videoRatio);
		lp.height = (parentRatio > videoRatio) ? parent.getHeight() : Math.round(((float) parent.getWidth()) / videoRatio);
	} else {
		boolean full = layout == VIDEO_LAYOUT_STRETCH;
		lp.width = (full || windowRatio < videoRatio) ? windowWidth : (int) (videoRatio * windowHeight);
		lp.height = (full || windowRatio > videoRatio) ? windowHeight : (int) (windowWidth / videoRatio);
	}
	setLayoutParams(lp);
	getHolder().setFixedSize(mSurfaceWidth, mSurfaceHeight);
   Log.d("VIDEO: %dx%dx%f, Surface: %dx%d, LP: %dx%d, Window: %dx%dx%f", mVideoWidth, mVideoHeight, mVideoAspectRatio, mSurfaceWidth, mSurfaceHeight, lp.width, lp.height, windowWidth, windowHeight, windowRatio);
   mVideoLayout = layout;
   mAspectRatio = aspectRatio;
 }
 
Example 25
Source Project: MyHearts   Source File: VideoView.java    License: Apache License 2.0 5 votes vote down vote up
public void suspend() {
  if (isInPlaybackState()) {
    release(false);
    mCurrentState = STATE_SUSPEND_UNSUPPORTED;
    Log.d("Unable to suspend video. Release MediaPlayer.");
  }
}
 
Example 26
Source Project: HPlayer   Source File: MediaPlayer.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Default constructor. The same as Android's MediaPlayer().
 * <p>
 * When done with the MediaPlayer, you should call {@link #release()}, to free
 * the resources. If not released, too many MediaPlayer instances may result
 * in an exception.
 * </p>
 *
 * @param preferHWDecoder MediaPlayer will try to use hardware accelerated decoder if true
 */
public MediaPlayer(Context ctx, boolean preferHWDecoder) {
  mContext = ctx;

  String LIB_ROOT = Vitamio.getLibraryPath();

  if (preferHWDecoder) {
    if (!NATIVE_OMX_LOADED.get()) {
      if (Build.VERSION.SDK_INT > 17)
        loadOMX_native( LIB_ROOT + "libOMX.18.so");
      
      else if (Build.VERSION.SDK_INT > 13)
        loadOMX_native( LIB_ROOT +  "libOMX.14.so");
      else if (Build.VERSION.SDK_INT > 10)
        loadOMX_native( LIB_ROOT + "libOMX.11.so");
      else
        loadOMX_native( LIB_ROOT +  "libOMX.9.so");
      NATIVE_OMX_LOADED.set(true);
    }
  } else {
    try {
      unloadOMX_native();
    } catch (UnsatisfiedLinkError e) {
      Log.e("unloadOMX failed %s", e.toString());
    }
    NATIVE_OMX_LOADED.set(false);
  }

  Looper looper;
  if ((looper = Looper.myLooper()) != null)
    mEventHandler = new EventHandler(this, looper);
  else if ((looper = Looper.getMainLooper()) != null)
    mEventHandler = new EventHandler(this, looper);
  else
    mEventHandler = null;

  native_init();
}
 
Example 27
Source Project: HPlayer   Source File: MediaPlayer.java    License: Apache License 2.0 5 votes vote down vote up
private static void postEventFromNative(Object mediaplayer_ref, int what, int arg1, int arg2, Object obj) {
  MediaPlayer mp = (MediaPlayer) (mediaplayer_ref);
  if (mp == null)
    return;

  try {
      //synchronized (mp.mEventHandler) {
      if (mp.mEventHandler != null) {
        Message m = mp.mEventHandler.obtainMessage(what, arg1, arg2, obj);
        mp.mEventHandler.sendMessage(m);
      }
  } catch (Exception e) {
      Log.e("exception: " + e);
  }
}
 
Example 28
Source Project: HPlayer   Source File: MediaPlayer.java    License: Apache License 2.0 5 votes vote down vote up
private void closeFD() {
  if (mFD != null) {
    try {
      mFD.close();
    } catch (IOException e) {
      Log.e("closeFD", e);
    }
    mFD = null;
  }
}
 
Example 29
Source Project: NetEasyNews   Source File: MediaScanner.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void handleStringTag(String name, byte[] valueBytes, String valueEncoding) {
  String value;
  try {
    value = new String(valueBytes, valueEncoding);
  } catch (Exception e) {
    Log.e("handleStringTag", e);
    value = new String(valueBytes);
  }
  Log.i("%s : %s", name, value);

  if (name.equalsIgnoreCase("title")) {
    mTitle = value;
  } else if (name.equalsIgnoreCase("artist")) {
    mArtist = value.trim();
  } else if (name.equalsIgnoreCase("albumartist")) {
    if (TextUtils.isEmpty(mArtist))
      mArtist = value.trim();
  } else if (name.equalsIgnoreCase("album")) {
    mAlbum = value.trim();
  } else if (name.equalsIgnoreCase("language")) {
    mLanguage = value.trim();
  } else if (name.equalsIgnoreCase("duration")) {
    mDuration = parseSubstring(value, 0, 0);
  } else if (name.equalsIgnoreCase("width")) {
    mWidth = parseSubstring(value, 0, 0);
  } else if (name.equalsIgnoreCase("height")) {
    mHeight = parseSubstring(value, 0, 0);
  }
}
 
Example 30
Source Project: HPlayer   Source File: MediaPlayer.java    License: Apache License 2.0 5 votes vote down vote up
public int audioTrackInit() {
//	  Log.e("  ffff mediaplayer audiotrackinit start .  sampleRateInHz:=" + sampleRateInHz + " channels:=" + channels );
	    audioTrackRelease();
	    int channelConfig = channels >= 2 ? AudioFormat.CHANNEL_OUT_STEREO : AudioFormat.CHANNEL_OUT_MONO;
	    try {
	      mAudioTrackBufferSize = AudioTrack.getMinBufferSize(sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT);
	      mAudioTrack = new AudioTrack(AudioManager.STREAM_MUSIC, sampleRateInHz, channelConfig, AudioFormat.ENCODING_PCM_16BIT, mAudioTrackBufferSize, AudioTrack.MODE_STREAM);
	    } catch (Exception e) {
	      mAudioTrackBufferSize = 0;
	      Log.e("audioTrackInit", e);
	    }
	    return mAudioTrackBufferSize;
	  }