Skip to content

Commit

Permalink
Merge pull request #53 from jpxiong/master
Browse files Browse the repository at this point in the history
release v1.1.6
  • Loading branch information
jpxiong committed Mar 5, 2016
2 parents 511ed62 + a88b6d1 commit 9b6f284
Show file tree
Hide file tree
Showing 19 changed files with 231 additions and 14 deletions.
2 changes: 1 addition & 1 deletion PLDroidPlayerDemo/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile files('libs/ijkmediaplayer.jar')
compile files('libs/pldroid-player-1.1.4.jar')
compile files('libs/pldroid-player-1.1.6.jar')
}
Binary file modified PLDroidPlayerDemo/app/libs/ijkmediaplayer.jar
Binary file not shown.
Binary file removed PLDroidPlayerDemo/app/libs/pldroid-player-1.1.4.jar
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.Toast;

import com.pili.pldroid.player.AVOptions;
import com.pili.pldroid.player.PlayerCode;
import com.pili.pldroid.player.SharedLibraryNameHelper;
import com.pili.pldroid.player.common.Util;
import com.pili.pldroid.player.widget.VideoView;
import com.pili.pldroid.playerdemo.R;
import com.pili.pldroid.playerdemo.widget.AspectLayout;
import com.pili.pldroid.playerdemo.widget.MediaController;

import tv.danmaku.ijk.media.player.IMediaPlayer;
Expand All @@ -23,13 +29,17 @@ public class VideoPlayerActivity extends Activity implements
IjkMediaPlayer.OnCompletionListener,
IjkMediaPlayer.OnInfoListener,
IjkMediaPlayer.OnErrorListener,
IjkMediaPlayer.OnPreparedListener {
IjkMediaPlayer.OnVideoSizeChangedListener,
IjkMediaPlayer.OnPreparedListener{
private static final String TAG = "VideoPlayerActivity";
private static final int REQ_DELAY_MILLS = 3000;

private VideoView mVideoView;
private View mBufferingIndicator;
private MediaController mMediaController;
private AspectLayout mAspectLayout;
private ViewGroup.LayoutParams mLayoutParams;
private Pair<Integer, Integer> mScreenSize;

private String mVideoPath;
private Button mBackBtn;
Expand All @@ -54,6 +64,8 @@ protected void onCreate(Bundle savedInstanceState) {
mVideoPath = intent.getDataString();
}

mAspectLayout = (AspectLayout)findViewById(R.id.aspect_layout);

mBackBtn = (Button) findViewById(R.id.back_btn);
mBackBtn.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -76,18 +88,23 @@ public void onClick(View view) {
}
mMediaController = new MediaController(this, useFastForward, disableProgressBar);

// SharedLibraryNameHelper.getInstance().renameSharedLibrary("pldroidplayer_v7a");

// mVideoView = (VideoTextureView) findViewById(R.id.video_view);
mVideoView = (VideoView) findViewById(R.id.video_view);
// mVideoView.setVideoPath(mVideoPath);
// mVideoView.start();
mMediaController.setMediaPlayer(mVideoView);
mVideoView.setMediaController(mMediaController);
// mVideoView.setMediaBufferingIndicator(mBufferingIndicator);
mVideoView.setMediaBufferingIndicator(mBufferingIndicator);

AVOptions options = new AVOptions();
options.setInteger(AVOptions.KEY_MEDIACODEC, 1); // 1 -> enable, 0 -> disable
options.setInteger(AVOptions.KEY_MEDIACODEC, 0); // 1 -> enable, 0 -> disable

Log.i(TAG, "mIsLiveStream:" + mIsLiveStream);
if (mIsLiveStream) {
options.setInteger(AVOptions.KEY_BUFFER_TIME, 1000); // the unit of buffer time is ms
options.setInteger(AVOptions.KEY_GET_AV_FRAME_TIMEOUT, 8 * 1000); // the unit of timeout is ms
options.setInteger(AVOptions.KEY_GET_AV_FRAME_TIMEOUT, 10 * 1000); // the unit of timeout is ms
options.setString(AVOptions.KEY_FFLAGS, AVOptions.VALUE_FFLAGS_NOBUFFER); // "nobuffer"
options.setInteger(AVOptions.KEY_LIVE_STREAMING, 1);
}
Expand All @@ -100,6 +117,7 @@ public void onClick(View view) {
mVideoView.setOnCompletionListener(this);
mVideoView.setOnInfoListener(this);
mVideoView.setOnPreparedListener(this);
mVideoView.setOnVideoSizeChangedListener(this);

mVideoView.requestFocus();
// mVideoView.start();
Expand All @@ -111,6 +129,7 @@ public void onCompletion(IMediaPlayer mp) {
Log.d(TAG, "onCompletion");
mIsCompleted = true;
mBufferingIndicator.setVisibility(View.GONE);
mVideoView.start();
}

@Override
Expand Down Expand Up @@ -150,6 +169,8 @@ public void run() {
@Override
public boolean onInfo(IMediaPlayer mp, int what, int extra) {
Log.d(TAG, "onInfo what=" + what + ", extra=" + extra);


if (what == IMediaPlayer.MEDIA_INFO_BUFFERING_START) {
Log.i(TAG, "onInfo: (MEDIA_INFO_BUFFERING_START)");
if (mBufferingIndicator != null)
Expand All @@ -158,6 +179,12 @@ public boolean onInfo(IMediaPlayer mp, int what, int extra) {
Log.i(TAG, "onInfo: (MEDIA_INFO_BUFFERING_END)");
if (mBufferingIndicator != null)
mBufferingIndicator.setVisibility(View.GONE);
} else if (what == IMediaPlayer.MEDIA_INFO_AUDIO_RENDERING_START) {
Toast.makeText(this, "Audio Start", Toast.LENGTH_LONG).show();
Log.i(TAG, "duration:" + mVideoView.getDuration());
} else if (what == IMediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {
Toast.makeText(this, "Video Start", Toast.LENGTH_LONG).show();
Log.i(TAG, "duration:" + mVideoView.getDuration());
}
return true;
}
Expand Down Expand Up @@ -189,4 +216,32 @@ public void onPause() {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

@Override
public void onVideoSizeChanged(IMediaPlayer iMediaPlayer, int width, int height, int sarNum, int sarDen) {
Log.i(TAG, "onVideoSizeChanged " + iMediaPlayer.getVideoWidth() + "x" + iMediaPlayer.getVideoHeight() + ",width:" + width + ",height:" + height + ",sarDen:" + sarDen + ",sarNum:" + sarNum);
if (width > height) {
// land video
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
mScreenSize = Util.getResolution(this);
} else {
// port video
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
mScreenSize = Util.getResolution(this);
}

if (width < mScreenSize.first) {
height = mScreenSize.first * height / width;
width = mScreenSize.first;
}

if (width * height < mScreenSize.first * mScreenSize.second) {
width = mScreenSize.second * width / height;
height = mScreenSize.second;
}

mLayoutParams = mAspectLayout.getLayoutParams();
mLayoutParams.width = width;
mLayoutParams.height = height;
mAspectLayout.setLayoutParams(mLayoutParams);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.pili.pldroid.playerdemo.widget;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Pair;
import android.view.View;
import android.widget.RelativeLayout;

import com.pili.pldroid.player.common.Util;

/**
* Created by jerikc on 15/11/22.
*/
public class AspectLayout extends RelativeLayout {
private static final String TAG = "AspectLayout";

private int mWidthMeasureSpec;

private int mRootHeight = 0;
private int mRootWidth = 0;

public AspectLayout(Context context) {
super(context);
initialize(context);
}

public AspectLayout(Context context, AttributeSet attrs) {
super(context, attrs);
initialize(context);
}

public AspectLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initialize(context);
}

private void initialize(Context ctx) {
}

@TargetApi(21)
public AspectLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Log.d(TAG, "onMeasure" + " width=[" + MeasureSpec.toString(widthMeasureSpec) +
"] height=[" + View.MeasureSpec.toString(heightMeasureSpec) + "]");

Rect r = new Rect();
getWindowVisibleDisplayFrame(r);
Pair<Integer, Integer> screenSize = Util.getResolution(getContext());

if (mRootWidth == 0 && mRootHeight == 0) {
mRootWidth = getRootView().getWidth();
mRootHeight = getRootView().getHeight();
}
int totalHeight = 0;

if (screenSize.first > screenSize.second) {
// land
totalHeight = mRootWidth > mRootHeight ? mRootHeight : mRootWidth;
} else {
// port
totalHeight = mRootWidth < mRootHeight ? mRootHeight : mRootWidth;
}

int nowHeight = r.bottom - r.top;

if (totalHeight - nowHeight > totalHeight / 4) {
// soft keyboard show
super.onMeasure(mWidthMeasureSpec, MeasureSpec.makeMeasureSpec(nowHeight + totalHeight - nowHeight, MeasureSpec.EXACTLY));
return;
} else {
// soft keyboard hide
}

mWidthMeasureSpec = widthMeasureSpec;

super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified PLDroidPlayerDemo/app/src/main/jniLibs/x86/libpldroidplayer.so
Binary file not shown.
23 changes: 19 additions & 4 deletions PLDroidPlayerDemo/app/src/main/res/layout/activity_player.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,22 @@
android:layout_height="match_parent"
android:background="@color/background_material_light" >

<com.pili.pldroid.player.widget.VideoView
android:id="@+id/video_view"
<com.pili.pldroid.playerdemo.widget.AspectLayout
android:id="@+id/aspect_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true" />
android:layout_height="match_parent">
<com.pili.pldroid.player.widget.VideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"

android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
/>
</com.pili.pldroid.playerdemo.widget.AspectLayout>

<Button
android:id="@+id/back_btn"
Expand All @@ -18,6 +29,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<EditText
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:id="@+id/buffering_indicator"
android:layout_width="wrap_content"
Expand Down
52 changes: 48 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ PLDroidPlayer 是一个适用于 Android 的音视频播放器 SDK,可高度
### 项目配置
`releases/` 目录获取:

- pldroid-player-xxx.jar
- pldroid-player-xxx.jar
- ijkmediaplayer-xxx.jar
- armeabi-v7a/libpldroidplayer.so
- arm64-v8a/libpldroidplayer.so
Expand Down Expand Up @@ -82,13 +82,15 @@ PLDroidPlayer 是一个适用于 Android 的音视频播放器 SDK,可高度
public class VideoPlayerActivity extends Activity implements
OnCompletionListener,
OnInfoListener,
OnVideoSizeChangedListener,
OnErrorListener,
OnPreparedListener {
...
mVideoView.setOnErrorListener(this);
mVideoView.setOnCompletionListener(this);
mVideoView.setOnInfoListener(this);
mVideoView.setOnPreparedListener(this);
mVideoView.setOnVideoSizeChangedListener(this);
...

@Override
Expand All @@ -98,20 +100,53 @@ public void onCompletion(IMediaPlayer mp) {

@Override
public boolean onError(IMediaPlayer mp, int what, int extra) {
...
if (what == -10000) {
switch (extra) {
case PlayerCode.EXTRA_CODE_404_NOT_FOUND:
break;
case PlayerCode.EXTRA_CODE_CONNECTION_REFUSED:
break;
case PlayerCode.EXTRA_CODE_CONNECTION_TIMEOUT:
break;
case PlayerCode.EXTRA_CODE_EMPTY_PLAYLIST:
break;
case PlayerCode.EXTRA_CODE_INVALID_URI:
break;
case PlayerCode.EXTRA_CODE_IO_ERROR:
break;
case PlayerCode.EXTRA_CODE_STREAM_DISCONNECTED:
break;
}
}
}

@Override
public boolean onInfo(IMediaPlayer mp, int what, int extra) {
...
switch (what) {
case IMediaPlayer.MEDIA_INFO_BUFFERING_START:
break;
case IMediaPlayer.MEDIA_INFO_BUFFERING_END:
break;
case IMediaPlayer.MEDIA_INFO_AUDIO_RENDERING_START:
break;
case IMediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START:
break;
}
}

@Override
public void onPrepared(IMediaPlayer mp) {
...
}

@Override
public void onVideoSizeChanged(IMediaPlayer iMediaPlayer, int width, int height, int sarNum, int sarDen) {
...
}
```



5 设置 `AVOptions`
```JAVA
// Tip: you can custom the variable depending on your situation
Expand All @@ -134,7 +169,7 @@ mAudioPlayer.setAVOptions(options);
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
Expand Down Expand Up @@ -189,6 +224,14 @@ mAudioPlayer.setAVOptions(options);

### 播放器

* 1.1.6 ([Release Notes][8])
- 发布 pldroid-player-1.1.6.jar
- 更新 libpldroidplayer.so
- 更新 ijkmediaplayer.jar
- 新增 `OnVideoSizeChangedListener#onVideoSizeChanged(IMediaPlayer, int, int, int, int)` 回调
- 修复概率性无视频有音频的现象
- 新增全屏播放 Demo 展示代码

* 1.1.4 ([Release Notes][7])
- 发布 pldroid-player-1.1.4.jar
- 更新 libpldroidplayer.so
Expand Down Expand Up @@ -249,3 +292,4 @@ mAudioPlayer.setAVOptions(options);
[5]: /ReleaseNotes/release-notes-1.1.2.md
[6]: /ReleaseNotes/release-notes-1.1.3.md
[7]: /ReleaseNotes/release-notes-1.1.4.md
[8]: /ReleaseNotes/release-notes-1.1.6.md
Loading

0 comments on commit 9b6f284

Please sign in to comment.