io.vov.vitamio.utils.Log Java Examples

The following examples show how to use io.vov.vitamio.utils.Log. 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 File: MediaScanner.java    From NetEasyNews with 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 #2
Source File: MediaScanner.java    From video-player with 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 #3
Source File: MediaPlayer.java    From video-player with 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 #4
Source File: MediaController.java    From video-player with 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 #5
Source File: MediaPlayer.java    From video-player with 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 #6
Source File: VideoView.java    From video-player with 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 #7
Source File: VideoView.java    From MyHearts with 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 #8
Source File: VideoView.java    From NetEasyNews with 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 #9
Source File: MediaController.java    From MyHearts with 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 #10
Source File: MediaScanner.java    From HPlayer with 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 #11
Source File: MediaScanner.java    From MyHearts with 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 #12
Source File: VideoView.java    From HPlayer with 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 #13
Source File: MediaPlayer.java    From NetEasyNews with 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 #14
Source File: MediaController.java    From HPlayer with 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 #15
Source File: MediaPlayer.java    From MyHearts with Apache License 2.0 6 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 #16
Source File: MediaPlayer.java    From MyHearts with 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 #17
Source File: MediaPlayer.java    From NetEasyNews with GNU General Public License v3.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 File: MediaPlayer.java    From NetEasyNews with GNU General Public License v3.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 #19
Source File: VideoView.java    From NetEasyNews with GNU General Public License v3.0 5 votes vote down vote up
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
  Log.d("onVideoSizeChanged: (%dx%d)", width, height);
  mVideoWidth = mp.getVideoWidth();
  mVideoHeight = mp.getVideoHeight();
  mVideoAspectRatio = mp.getVideoAspectRatio();
  if (mVideoWidth != 0 && mVideoHeight != 0)
    setVideoLayout(mVideoLayout, mAspectRatio);
}
 
Example #20
Source File: VideoView.java    From video-player with MIT License 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 #21
Source File: MediaPlayer.java    From NetEasyNews with GNU General Public License v3.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 #22
Source File: VideoView.java    From HPlayer with Apache License 2.0 5 votes vote down vote up
public void onPrepared(MediaPlayer mp) {
   Log.d("onPrepared");
if (false) {
	stopPlayback();
	return;
}
mCurrentState = STATE_PREPARED;
// mTargetState = STATE_PLAYING;

// Get the capabilities of the player for this stream
//TODO mCanPause

   if (mOnPreparedListener != null)
     mOnPreparedListener.onPrepared(mMediaPlayer);
   if (mMediaController != null)
     mMediaController.setEnabled(true);
   mVideoWidth = mp.getVideoWidth();
   mVideoHeight = mp.getVideoHeight();
   mVideoAspectRatio = mp.getVideoAspectRatio();

   long seekToPosition = mSeekWhenPrepared;
   if (seekToPosition != 0)
     seekTo(seekToPosition);

   if (mVideoWidth != 0 && mVideoHeight != 0) {
     setVideoLayout(mVideoLayout, mAspectRatio);
     if (mSurfaceWidth == mVideoWidth && mSurfaceHeight == mVideoHeight) {
       if (mTargetState == STATE_PLAYING) {
         start();
         if (mMediaController != null)
           mMediaController.show();
       } else if (!isPlaying() && (seekToPosition != 0 || getCurrentPosition() > 0)) {
         if (mMediaController != null)
           mMediaController.show(0);
       }
     }
   } else if (mTargetState == STATE_PLAYING) {
     start();
   }
 }
 
Example #23
Source File: VideoView.java    From NetEasyNews with GNU General Public License v3.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 File: MediaPlayer.java    From video-player with MIT License 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 #25
Source File: VideoView.java    From NetEasyNews with GNU General Public License v3.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 #26
Source File: MediaPlayer.java    From video-player with MIT License 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 #27
Source File: VideoView.java    From NetEasyNews with GNU General Public License v3.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 #28
Source File: VideoView.java    From NetEasyNews with GNU General Public License v3.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 #29
Source File: VideoView.java    From HPlayer with 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 #30
Source File: VideoView.java    From HPlayer with 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;
}