提交 d763a916 编写于 作者: S shuyu

兼容Appbar中使用 (2017-07-05)

上级 ad326ab3
......@@ -2,6 +2,9 @@
### 1.6.9()
* 兼容Appbar中使用,感谢[@loveRose](https://github.com/loveRose)
* 修改setup的设置参数。
* 升级修改所有回调接口,回调接口中返回当前播放器。
* 非全屏播放器可获取全屏播放器对象。
```
/**
......
......@@ -172,7 +172,13 @@ public abstract class GSYVideoPlayer extends GSYBaseVideoPlayer implements View.
}
protected void init(Context context) {
this.mContext = context;
if (getActivityContext() != null) {
this.mContext = getActivityContext();
} else {
this.mContext = context;
}
View.inflate(context, getLayoutId(), this);
mStartButton = findViewById(R.id.start);
mSmallClose = findViewById(R.id.small_close);
......@@ -196,11 +202,11 @@ public abstract class GSYVideoPlayer extends GSYBaseVideoPlayer implements View.
mTextureViewContainer.setOnTouchListener(this);
mFullscreenButton.setOnTouchListener(this);
mScreenWidth = getContext().getResources().getDisplayMetrics().widthPixels;
mScreenHeight = getContext().getResources().getDisplayMetrics().heightPixels;
mAudioManager = (AudioManager) getContext().getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
mScreenWidth = getActivityContext().getResources().getDisplayMetrics().widthPixels;
mScreenHeight = getActivityContext().getResources().getDisplayMetrics().heightPixels;
mAudioManager = (AudioManager) getActivityContext().getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
mSeekEndOffset = CommonUtil.dip2px(getContext(), 50);
mSeekEndOffset = CommonUtil.dip2px(getActivityContext(), 50);
}
......@@ -217,7 +223,7 @@ public abstract class GSYVideoPlayer extends GSYBaseVideoPlayer implements View.
*
* @param url 播放url
* @param cacheWithPlay 是否边播边缓存
* @param title title
* @param title title
* @return
*/
public boolean setUp(String url, boolean cacheWithPlay, String title) {
......@@ -232,7 +238,7 @@ public abstract class GSYVideoPlayer extends GSYBaseVideoPlayer implements View.
* @param cacheWithPlay 是否边播边缓存
* @param cachePath 缓存路径,如果是M3U8或者HLS,请设置为false
* @param mapHeadData 头部信息
* @param title title
* @param title title
* @return
*/
@Override
......@@ -252,7 +258,7 @@ public abstract class GSYVideoPlayer extends GSYBaseVideoPlayer implements View.
* @param url 播放url
* @param cacheWithPlay 是否边播边缓存
* @param cachePath 缓存路径,如果是M3U8或者HLS,请设置为false
* @param title title
* @param title title
* @return
*/
@Override
......@@ -265,7 +271,7 @@ public abstract class GSYVideoPlayer extends GSYBaseVideoPlayer implements View.
return false;
mCurrentState = CURRENT_STATE_NORMAL;
if (cacheWithPlay && url.startsWith("http") && !url.contains("127.0.0.1") && !url.contains(".m3u8")) {
HttpProxyCacheServer proxy = GSYVideoManager.getProxy(getContext().getApplicationContext(), cachePath);
HttpProxyCacheServer proxy = GSYVideoManager.getProxy(getActivityContext().getApplicationContext(), cachePath);
//此处转换了url,然后再赋值给mUrl。
url = proxy.getProxyUrl(url);
mCacheFile = (!url.startsWith("http"));
......@@ -333,7 +339,7 @@ public abstract class GSYVideoPlayer extends GSYBaseVideoPlayer implements View.
}
if (i == R.id.start) {
if (TextUtils.isEmpty(mUrl)) {
Toast.makeText(getContext(), getResources().getString(R.string.no_url), Toast.LENGTH_SHORT).show();
Toast.makeText(getActivityContext(), getResources().getString(R.string.no_url), Toast.LENGTH_SHORT).show();
return;
}
if (mCurrentState == CURRENT_STATE_NORMAL || mCurrentState == CURRENT_STATE_ERROR) {
......@@ -1058,7 +1064,7 @@ public abstract class GSYVideoPlayer extends GSYBaseVideoPlayer implements View.
CommonUtil.deleteFile(path);
} else {
String path = StorageUtils.getIndividualCacheDirectory
(getContext().getApplicationContext()).getAbsolutePath()
(getActivityContext().getApplicationContext()).getAbsolutePath()
+ File.separator + name + ".download";
CommonUtil.deleteFile(path);
}
......@@ -1232,7 +1238,7 @@ public abstract class GSYVideoPlayer extends GSYBaseVideoPlayer implements View.
*/
protected void createNetWorkState() {
if (mNetInfoModule == null) {
mNetInfoModule = new NetInfoModule(getContext().getApplicationContext(), new NetInfoModule.NetChangeListener() {
mNetInfoModule = new NetInfoModule(getActivityContext().getApplicationContext(), new NetInfoModule.NetChangeListener() {
@Override
public void changed(String state) {
if (!mNetSate.equals(state)) {
......
......@@ -255,4 +255,15 @@ public class CommonUtil {
}
}
}
public static Activity getActivityContext(Context context) {
if (context == null)
return null;
else if (context instanceof Activity)
return (Activity) context;
else if (context instanceof ContextWrapper)
return scanForActivity(((ContextWrapper) context).getBaseContext());
return null;
}
}
......@@ -72,7 +72,7 @@ public class CustomGSYVideoPlayer extends StandardGSYVideoPlayer {
mPreviewLayout.removeAllViews();
}
mPreviewTexture = null;
mPreviewTexture = new GSYTextureView(getContext());
mPreviewTexture = new GSYTextureView(getActivityContext());
mPreviewTexture.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
......
......@@ -169,6 +169,9 @@ public abstract class GSYBaseVideoPlayer extends FrameLayout implements GSYMedia
super(context, attrs, defStyleAttr);
}
public Context getActivityContext() {
return CommonUtil.getActivityContext(getContext());
}
private ViewGroup getViewGroup() {
return (ViewGroup) (CommonUtil.scanForActivity(getContext())).findViewById(Window.ID_ANDROID_CONTENT);
......@@ -333,10 +336,10 @@ public abstract class GSYBaseVideoPlayer extends FrameLayout implements GSYMedia
final GSYBaseVideoPlayer gsyVideoPlayer;
if (!hadNewConstructor) {
constructor = (Constructor<GSYBaseVideoPlayer>) GSYBaseVideoPlayer.this.getClass().getConstructor(Context.class);
gsyVideoPlayer = constructor.newInstance(getContext());
gsyVideoPlayer = constructor.newInstance(getActivityContext());
} else {
constructor = (Constructor<GSYBaseVideoPlayer>) GSYBaseVideoPlayer.this.getClass().getConstructor(Context.class, Boolean.class);
gsyVideoPlayer = constructor.newInstance(getContext(), true);
gsyVideoPlayer = constructor.newInstance(getActivityContext(), true);
}
gsyVideoPlayer.setId(FULLSCREEN_ID);
......@@ -540,7 +543,7 @@ public abstract class GSYBaseVideoPlayer extends FrameLayout implements GSYMedia
try {
Constructor<GSYBaseVideoPlayer> constructor = (Constructor<GSYBaseVideoPlayer>) GSYBaseVideoPlayer.this.getClass().getConstructor(Context.class);
GSYBaseVideoPlayer gsyVideoPlayer = constructor.newInstance(getContext());
GSYBaseVideoPlayer gsyVideoPlayer = constructor.newInstance(getActivityContext());
gsyVideoPlayer.setId(SMALL_ID);
FrameLayout.LayoutParams lpParent = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
......
......@@ -297,11 +297,11 @@ public class StandardGSYVideoPlayer extends GSYVideoPlayer {
return;
}
if (TextUtils.isEmpty(mUrl)) {
Toast.makeText(getContext(), getResources().getString(R.string.no_url), Toast.LENGTH_SHORT).show();
Toast.makeText(getActivityContext(), getResources().getString(R.string.no_url), Toast.LENGTH_SHORT).show();
return;
}
if (mCurrentState == CURRENT_STATE_NORMAL) {
if (!mUrl.startsWith("file") && !CommonUtil.isWifiConnected(getContext()) && mNeedShowWifiTip) {
if (!mUrl.startsWith("file") && !CommonUtil.isWifiConnected(getActivityContext()) && mNeedShowWifiTip) {
showWifiDialog();
return;
}
......@@ -330,7 +330,7 @@ public class StandardGSYVideoPlayer extends GSYVideoPlayer {
Toast.makeText(mContext, getResources().getString(R.string.no_net), Toast.LENGTH_LONG).show();
return;
}
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
AlertDialog.Builder builder = new AlertDialog.Builder(getActivityContext());
builder.setMessage(getResources().getString(R.string.tips_not_wifi));
builder.setPositiveButton(getResources().getString(R.string.tips_not_wifi_confirm), new DialogInterface.OnClickListener() {
@Override
......@@ -643,7 +643,7 @@ public class StandardGSYVideoPlayer extends GSYVideoPlayer {
protected void showProgressDialog(float deltaX, String seekTime, int seekTimePosition, String totalTime, int totalTimeDuration) {
super.showProgressDialog(deltaX, seekTime, seekTimePosition, totalTime, totalTimeDuration);
if (mProgressDialog == null) {
View localView = LayoutInflater.from(getContext()).inflate(R.layout.video_progress_dialog, null);
View localView = LayoutInflater.from(getActivityContext()).inflate(R.layout.video_progress_dialog, null);
mDialogProgressBar = ((ProgressBar) localView.findViewById(R.id.duration_progressbar));
if (mDialogProgressBarDrawable != null) {
mDialogProgressBar.setProgressDrawable(mDialogProgressBarDrawable);
......@@ -651,7 +651,7 @@ public class StandardGSYVideoPlayer extends GSYVideoPlayer {
mDialogSeekTime = ((TextView) localView.findViewById(R.id.tv_current));
mDialogTotalTime = ((TextView) localView.findViewById(R.id.tv_duration));
mDialogIcon = ((ImageView) localView.findViewById(R.id.duration_image_tip));
mProgressDialog = new Dialog(getContext(), R.style.video_style_dialog_progress);
mProgressDialog = new Dialog(getActivityContext(), R.style.video_style_dialog_progress);
mProgressDialog.setContentView(localView);
mProgressDialog.getWindow().addFlags(Window.FEATURE_ACTION_BAR);
mProgressDialog.getWindow().addFlags(32);
......@@ -702,12 +702,12 @@ public class StandardGSYVideoPlayer extends GSYVideoPlayer {
protected void showVolumeDialog(float deltaY, int volumePercent) {
super.showVolumeDialog(deltaY, volumePercent);
if (mVolumeDialog == null) {
View localView = LayoutInflater.from(getContext()).inflate(R.layout.video_volume_dialog, null);
View localView = LayoutInflater.from(getActivityContext()).inflate(R.layout.video_volume_dialog, null);
mDialogVolumeProgressBar = ((ProgressBar) localView.findViewById(R.id.volume_progressbar));
if (mVolumeProgressDrawable != null) {
mDialogVolumeProgressBar.setProgressDrawable(mVolumeProgressDrawable);
}
mVolumeDialog = new Dialog(getContext(), R.style.video_style_dialog_progress);
mVolumeDialog = new Dialog(getActivityContext(), R.style.video_style_dialog_progress);
mVolumeDialog.setContentView(localView);
mVolumeDialog.getWindow().addFlags(8);
mVolumeDialog.getWindow().addFlags(32);
......@@ -742,9 +742,9 @@ public class StandardGSYVideoPlayer extends GSYVideoPlayer {
@Override
protected void showBrightnessDialog(float percent) {
if (mBrightnessDialog == null) {
View localView = LayoutInflater.from(getContext()).inflate(R.layout.video_brightness, null);
View localView = LayoutInflater.from(getActivityContext()).inflate(R.layout.video_brightness, null);
mBrightnessDialogTv = (TextView) localView.findViewById(R.id.app_video_brightness);
mBrightnessDialog = new Dialog(getContext(), R.style.video_style_dialog_progress);
mBrightnessDialog = new Dialog(getActivityContext(), R.style.video_style_dialog_progress);
mBrightnessDialog.setContentView(localView);
mBrightnessDialog.getWindow().addFlags(8);
mBrightnessDialog.getWindow().addFlags(32);
......@@ -918,8 +918,8 @@ public class StandardGSYVideoPlayer extends GSYVideoPlayer {
if (mCurrentState != CURRENT_STATE_NORMAL
&& mCurrentState != CURRENT_STATE_ERROR
&& mCurrentState != CURRENT_STATE_AUTO_COMPLETE) {
if (getContext() != null && getContext() instanceof Activity) {
((Activity) getContext()).runOnUiThread(new Runnable() {
if (getActivityContext() != null) {
((Activity) getActivityContext()).runOnUiThread(new Runnable() {
@Override
public void run() {
hideAllWidget();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册