Commit 0d190060 authored by jianglx's avatar jianglx

添加im依赖包

parent b33ea9c2
......@@ -8,8 +8,8 @@ android {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
flavorDimensions "default"
versionCode 144
versionName "1.4.4"
versionCode 146
versionName "1.4.6"
multiDexEnabled true
ndk {
......
......@@ -190,10 +190,28 @@
android:screenOrientation="portrait"
android:theme="@android:style/Theme.Translucent.NoTitleBar" /> <!-- umShare 相关 end -->
<!--<activity-->
<!--android:name=".MainActivity"-->
<!--android:launchMode="singleTask"-->
<!--android:screenOrientation="portrait" />-->
 
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
android:screenOrientation="portrait" />
android:excludeFromRecents="true"
android:exported="true"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW"></action>
<category android:name="android.intent.category.DEFAULT"></category>
<category android:name="android.intent.category.BROWSABLE"></category>
<data
android:host="xxrvapp"
android:scheme="xinxinrvservice"></data>
</intent-filter>
</activity>
<activity
android:name="com.rv.home.rv.module.ui.login.LoginRvActivity"
android:screenOrientation="portrait" />
......
......@@ -33,6 +33,7 @@ import com.fanjun.keeplive.config.KeepLiveService;
import com.frame.base.url.Constance;
import com.frame.rv.config.RvFrameConfig;
import com.ruiwenliu.wrapper.MessageEventLogout;
import com.ruiwenliu.wrapper.MessageEventRemoteLogin;
import com.ruiwenliu.wrapper.SPConstance;
import com.ruiwenliu.wrapper.adapter.TabAdapter;
import com.ruiwenliu.wrapper.base.BaseActivity;
......@@ -174,7 +175,6 @@ public class MainActivity extends BaseActivity<CommonPresenter> {
@Override
protected void initView(Bundle savedInstanceState, TitleView titleView, Intent intent) {
registerReceiver();
updateAppUtils = UpdateAppUtils.from(MainActivity.this);
viewPager = findViewById(R.id.pager_view_fragment);
showTitle(false);
......@@ -579,8 +579,6 @@ public class MainActivity extends BaseActivity<CommonPresenter> {
private ServiceConnection imServiceConnection;
private RemoteReceiver receiver = null;
private void imLogin() {
if (!hasBindService && isLogin()) {
Map<String, Object> headMap = new LinkedHashMap<>();
......@@ -631,32 +629,8 @@ public class MainActivity extends BaseActivity<CommonPresenter> {
}
}
void destory() {
if (imServiceConnection != null) {
try {
unbindService(imServiceConnection);
} catch (Exception e) {
LogUtil.e("MainActivity", "destory" + e.getMessage());
}
}
AudioOrVideoController.init(getApplicationContext(), logoutListener).release();
EventBus.getDefault().unregister(this);
if (receiver != null) {
unregisterReceiver(receiver);
receiver = null;
}
}
private void registerReceiver() {
if (receiver == null) {
receiver = new RemoteReceiver(remoteListener);
}
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Constants.ACTIONS.ACTION_RECEIVE_REMOTE_LOGIN);
registerReceiver(receiver, intentFilter);
}
private RemoteReceiver.RemoteListener remoteListener = () -> {
@Subscribe(threadMode = ThreadMode.MAIN)
public void remoteLogin(MessageEventRemoteLogin remoteLogin){
//退出登录
Toast.makeText(getApplicationContext(), "账号远程登录", Toast.LENGTH_SHORT).show();
hasBindService = false;
......@@ -671,7 +645,19 @@ public class MainActivity extends BaseActivity<CommonPresenter> {
if (mAdapter != null) {
((MineFragment) mAdapter.getItem(4)).signOut();
}
};
}
void destory() {
if (imServiceConnection != null) {
try {
unbindService(imServiceConnection);
} catch (Exception e) {
LogUtil.e("MainActivity", "destory" + e.getMessage());
}
}
AudioOrVideoController.init(getApplicationContext(), logoutListener).release();
EventBus.getDefault().unregister(this);
}
private AudioOrVideoController.LogoutListener logoutListener = new AudioOrVideoController.LogoutListener() {
@Override
......
<resources>
<string name="app_name">滴房车(测试)</string>
<string name="share_install_key">7BBK22KKFH26KE</string>
<string name="share_install_scheme">epad4069</string>
<string name="share_install_key">B2BK2RRE67RHH7</string>
<string name="share_install_scheme">ceck9380</string>
</resources>
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
flavorDimensions "default"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
productFlavors {
//开发环境
dev {
}
sit {
}
pro {
}
}
}
dependencies {
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:28.0.0'
//事件总线
api "org.greenrobot:eventbus:$rootProject.ext.eventBusVersion"
}
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/Nathen/WorkEnv/android-sdk-macosx/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fm.jiecao.jcvideoplayer_lib">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
\ No newline at end of file
package fm.jiecao.jcvideoplayer_lib;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.ImageView;
/**
* 这个ImageView用作于聊天发送图片
* 做了一个类似QQ发送图片的背景效果
* 此控件由Liuxuan大神编写
* 2017-7-19
*/
public class ChatImageView extends ImageView {
private Paint mBitPaint;
private int mTotalWidth;
private int mTotalHeight;
private RectF mSrcRect;
private Path path;
private int triangleY;
private int radius;
private boolean direction;
private boolean mFreezesAnimation;
public ChatImageView(Context context) {
this(context, null, 0);
}
public ChatImageView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public ChatImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray ta = context.obtainStyledAttributes(attrs, new int[]{R.attr.chat_direction});
direction = ta.getBoolean(0, false);
initPaint();
}
private void initPaint() {
mBitPaint = new Paint();
mBitPaint.setAntiAlias(true); //设置画笔为无锯齿
mBitPaint.setColor(Color.parseColor("#EBEBEB")); //设置画笔颜色
mBitPaint.setStrokeWidth(1f); //线宽
mBitPaint.setStyle(Paint.Style.FILL); //填充
triangleY = 30;
radius = 10;
}
@Override
public void setImageDrawable(Drawable drawable) {
super.setImageDrawable(drawable);
invalidate();
}
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawPath(path, mBitPaint);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
mTotalWidth = w;
mTotalHeight = h;
if (direction) {
/* 圆角矩形 */
Path p = new Path();
RectF oval = new RectF(0, 0, mTotalWidth - 15, mTotalHeight);
p.addRoundRect(oval, radius, radius, Path.Direction.CCW);
/* 三角形 */
Path sanP = new Path();
sanP.moveTo(mTotalWidth - 15, triangleY);
sanP.lineTo(mTotalWidth, triangleY + 10);
sanP.lineTo(mTotalWidth - 15, triangleY + 20);
sanP.close();
/* 整个ImageView矩形 */
Path sizP = new Path();
RectF oo = new RectF(0, 0, mTotalWidth, mTotalHeight);
sizP.addRect(oo, Path.Direction.CCW);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
p.op(sanP, Path.Op.XOR);
sizP.op(p, Path.Op.DIFFERENCE);
}
path = sizP;
} else {
/* 圆角矩形 */
Path p = new Path();
RectF oval = new RectF(15, 0, mTotalWidth, mTotalHeight);
p.addRoundRect(oval, radius, radius, Path.Direction.CCW);
/* 三角形 */
Path sanP = new Path();
sanP.moveTo(15, triangleY);
sanP.lineTo(0, triangleY + 10);
sanP.lineTo(15, triangleY + 20);
sanP.close();
/* 整个ImageView矩形 */
Path sizP = new Path();
RectF oo = new RectF(0, 0, mTotalWidth, mTotalHeight);
sizP.addRect(oo, Path.Direction.CCW);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
p.op(sanP, Path.Op.XOR);
sizP.op(p, Path.Op.DIFFERENCE);
}
path = sizP;
}
}
/**
* @param y 三角形箭头与顶部的距离
*/
public void setTriangleY(int y) {
if (y < 30) {
triangleY = 30;
}
triangleY = y;
invalidate();
}
public void setRadius(int r) {
if (r > 100 || r < 5) {
r = 10;
}
radius = r;
invalidate();
}
public void setChatBackground(int color) {
mBitPaint.setColor(color);
invalidate();
}
/**
* @param b true = 右边
*/
public void setChatDirection(boolean b) {
direction = b;
invalidate();
}
}
package fm.jiecao.jcvideoplayer_lib;
/**
* Created by dty on 2015/11/8.
* 单个下载线程
*/
import android.util.Log;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.net.URL;
import java.net.URLConnection;
public class FileDownloadThread extends Thread {
private static final int BUFFER_SIZE = 1024;
private URL url;
private File file;
private int startPosition;
private int endPosition;
private int curPosition;
//用于标识当前线程是否下载完成
private boolean finished = false;
private int downloadSize = 0;
public FileDownloadThread(URL url, File file, int startPosition, int endPosition) {
this.url = url;
this.file = file;
this.startPosition = startPosition;
this.curPosition = startPosition;
this.endPosition = endPosition;
}
@Override
public void run() {
BufferedInputStream bis = null;
RandomAccessFile fos = null;
byte[] buf = new byte[BUFFER_SIZE];
URLConnection con = null;
try {
con = url.openConnection();
con.setAllowUserInteraction(true);
//设置当前线程下载的起点,终点
con.setRequestProperty("Range", "bytes=" + startPosition + "-" + endPosition);
//使用java中的RandomAccessFile 对文件进行随机读写操作
fos = new RandomAccessFile(file, "rw");
//设置开始写文件的位置
fos.seek(startPosition);
bis = new BufferedInputStream(con.getInputStream());
//开始循环以流的形式读写文件
while (curPosition < endPosition) {
int len = bis.read(buf, 0, BUFFER_SIZE);
if (len == -1) {
break;
}
fos.write(buf, 0, len);
curPosition = curPosition + len;
if (curPosition > endPosition) {
downloadSize += len - (curPosition - endPosition) + 1;
} else {
downloadSize += len;
}
}
//下载完成设为true
this.finished = true;
bis.close();
fos.close();
} catch (IOException e) {
Log.d(getName() + " Error:", e.getMessage());
}
}
public boolean isFinished() {
return finished;
}
public int getDownloadSize() {
return downloadSize;
}
}
\ No newline at end of file
package fm.jiecao.jcvideoplayer_lib;
import android.graphics.Point;
import android.graphics.SurfaceTexture;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.Surface;
import android.view.TextureView;
import java.lang.reflect.Method;
import java.util.Map;
/**
* <p>统一管理MediaPlayer的地方,只有一个mediaPlayer实例,那么不会有多个视频同时播放,也节省资源。</p>
* <p>Unified management MediaPlayer place, there is only one MediaPlayer instance, then there will be no more video broadcast at the same time, also save resources.</p>
* Created by Nathen
* On 2015/11/30 15:39
*/
public class JCMediaManager implements TextureView.SurfaceTextureListener, MediaPlayer.OnPreparedListener, MediaPlayer.OnCompletionListener, MediaPlayer.OnBufferingUpdateListener, MediaPlayer.OnSeekCompleteListener, MediaPlayer.OnErrorListener, MediaPlayer.OnInfoListener, MediaPlayer.OnVideoSizeChangedListener {
public static final int HANDLER_PREPARE = 0;
public static final int HANDLER_RELEASE = 2;
public static String TAG = "JieCaoVideoPlayer";
public static JCResizeTextureView textureView;
public static SurfaceTexture savedSurfaceTexture;
public static String CURRENT_PLAYING_URL;
public static boolean CURRENT_PLING_LOOP;
public static Map<String, String> MAP_HEADER_DATA;
private static JCMediaManager JCMediaManager;
private static OnJcvdListener mJcvdListener;
public MediaPlayer mediaPlayer = new MediaPlayer();
public int currentVideoWidth = 0;
public int currentVideoHeight = 0;
HandlerThread mMediaHandlerThread;
MediaHandler mMediaHandler;
Handler mainThreadHandler;
public JCMediaManager() {
mMediaHandlerThread = new HandlerThread(TAG);
mMediaHandlerThread.start();
mMediaHandler = new MediaHandler((mMediaHandlerThread.getLooper()));
mainThreadHandler = new Handler();
}
public static JCMediaManager instance() {
if (JCMediaManager == null) {
JCMediaManager = new JCMediaManager();
}
return JCMediaManager;
}
public static void addOnJcvdListener(OnJcvdListener listener) {
mJcvdListener = listener;
}
public Point getVideoSize() {
if (currentVideoWidth != 0 && currentVideoHeight != 0) {
return new Point(currentVideoWidth, currentVideoHeight);
} else {
return null;
}
}
public void prepare() {
releaseMediaPlayer();
Message msg = new Message();
msg.what = HANDLER_PREPARE;
mMediaHandler.sendMessage(msg);
Log.e("xuan", "jcm prepare: ");
}
public void releaseMediaPlayer() {
Message msg = new Message();
msg.what = HANDLER_RELEASE;
mMediaHandler.sendMessage(msg);
Log.e("xuan", "jcm releaseMediaPlayer: ");
}
// Todo create 2018.11.29 by zq 全屏->小窗 主动调用onCompletion方法,结束播放,在全屏模式下循环播放
public void recoverMediaPlayer() {
mediaPlayer.release();
onCompletion(mediaPlayer);
Log.e("xuan", "jcm recoverMediaPlayer: ");
}
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i1) {
Log.i(TAG, "onSurfaceTextureAvailable [" + this.hashCode() + "] ");
if (savedSurfaceTexture == null) {
savedSurfaceTexture = surfaceTexture;
prepare();
} else {
textureView.setSurfaceTexture(savedSurfaceTexture);
}
}
@Override
public void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int i, int i1) {
// 如果SurfaceTexture还没有更新Image,则记录SizeChanged事件,否则忽略
Log.i(TAG, "onSurfaceTextureSizeChanged [" + this.hashCode() + "] ");
}
@Override
public boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture) {
return savedSurfaceTexture == null;
}
@Override
public void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture) {
}
@Override
public void onPrepared(MediaPlayer mp) {
mediaPlayer.start();
mainThreadHandler.post(new Runnable() {
@Override
public void run() {
if (JCVideoPlayerManager.getCurrentJcvd() != null) {
JCVideoPlayerManager.getCurrentJcvd().onPrepared();
}
if (mJcvdListener != null) {
mJcvdListener.onPrepared();
}
}
});
}
@Override
public void onCompletion(MediaPlayer mp) {
mainThreadHandler.post(new Runnable() {
@Override
public void run() {
if (JCVideoPlayerManager.getCurrentJcvd() != null) {
JCVideoPlayerManager.getCurrentJcvd().onAutoCompletion();
}
if (mJcvdListener != null) {
mJcvdListener.onCompletion();
}
}
});
}
@Override
public void onBufferingUpdate(MediaPlayer mp, final int percent) {
mainThreadHandler.post(new Runnable() {
@Override
public void run() {
if (JCVideoPlayerManager.getCurrentJcvd() != null) {
JCVideoPlayerManager.getCurrentJcvd().setBufferProgress(percent);
}
}
});
}
@Override
public void onSeekComplete(MediaPlayer mp) {
mainThreadHandler.post(new Runnable() {
@Override
public void run() {
if (JCVideoPlayerManager.getCurrentJcvd() != null) {
JCVideoPlayerManager.getCurrentJcvd().onSeekComplete();
}
}
});
}
@Override
public boolean onError(MediaPlayer mp, final int what, final int extra) {
mainThreadHandler.post(new Runnable() {
@Override
public void run() {
if (JCVideoPlayerManager.getCurrentJcvd() != null) {
JCVideoPlayerManager.getCurrentJcvd().onError(what, extra);
}
if (mJcvdListener != null) {
mJcvdListener.onError();
}
}
});
return true;
}
@Override
public boolean onInfo(MediaPlayer mp, final int what, final int extra) {
mainThreadHandler.post(new Runnable() {
@Override
public void run() {
if (JCVideoPlayerManager.getCurrentJcvd() != null) {
JCVideoPlayerManager.getCurrentJcvd().onInfo(what, extra);
}
}
});
return false;
}
@Override
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
currentVideoWidth = width;
currentVideoHeight = height;
mainThreadHandler.post(new Runnable() {
@Override
public void run() {
if (JCVideoPlayerManager.getCurrentJcvd() != null) {
JCVideoPlayerManager.getCurrentJcvd().onVideoSizeChanged();
}
if (textureView != null) {
textureView.setVideoSize(getVideoSize());
}
}
});
}
public class MediaHandler extends Handler {
public MediaHandler(Looper looper) {
super(looper);
}
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
switch (msg.what) {
case HANDLER_PREPARE:
try {
currentVideoWidth = 0;
currentVideoHeight = 0;
mediaPlayer.release();
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
Class<MediaPlayer> clazz = MediaPlayer.class;
Method method = clazz.getDeclaredMethod("setDataSource", String.class, Map.class);
method.invoke(mediaPlayer, CURRENT_PLAYING_URL, MAP_HEADER_DATA);
mediaPlayer.setLooping(false);
mediaPlayer.setOnPreparedListener(JCMediaManager.this);
mediaPlayer.setOnCompletionListener(JCMediaManager.this);
mediaPlayer.setOnBufferingUpdateListener(JCMediaManager.this);
mediaPlayer.setScreenOnWhilePlaying(true);
mediaPlayer.setOnSeekCompleteListener(JCMediaManager.this);
mediaPlayer.setOnErrorListener(JCMediaManager.this);
mediaPlayer.setOnInfoListener(JCMediaManager.this);
mediaPlayer.setOnVideoSizeChangedListener(JCMediaManager.this);
mediaPlayer.prepareAsync();
if (savedSurfaceTexture != null) {
mediaPlayer.setSurface(new Surface(savedSurfaceTexture));
}
} catch (Exception e) {
e.printStackTrace();
Log.e("xuan", "handleMessage: Exception--->" + e.getMessage());
}
break;
case HANDLER_RELEASE:
mediaPlayer.release();
break;
}
}
}
}
package fm.jiecao.jcvideoplayer_lib;
import android.content.Context;
import android.graphics.Point;
import android.util.AttributeSet;
import android.util.Log;
import android.view.TextureView;
/**
* <p>参照Android系统的VideoView的onMeasure方法
* <br>注意!relativelayout中无法全屏,要嵌套一个linearlayout</p>
* <p>Referring Android system Video View of onMeasure method
* <br>NOTE! Can not fullscreen relativelayout, to nest a linearlayout</p>
* Created by Nathen
* On 2016/06/02 00:01
*/
public class JCResizeTextureView extends TextureView {
protected static final String TAG = "JCResizeTextureView";
// x as width, y as height
protected Point mVideoSize;
public JCResizeTextureView(Context context) {
super(context);
init();
}
public JCResizeTextureView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
mVideoSize = new Point(0, 0);
}
public void setVideoSize(Point videoSize) {
if (videoSize != null && !mVideoSize.equals(videoSize)) {
this.mVideoSize = videoSize;
requestLayout();
}
}
@Override
public void setRotation(float rotation) {
if (rotation != getRotation()) {
super.setRotation(rotation);
requestLayout();
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
Log.i(TAG, "onMeasure " + " [" + this.hashCode() + "] ");
int viewRotation = (int) getRotation();
int videoWidth = mVideoSize.x;
int videoHeight = mVideoSize.y;
Log.i(TAG, "videoWidth = " + videoWidth + ", " + "videoHeight = " + videoHeight);
Log.i(TAG, "viewRotation = " + viewRotation);
// 如果判断成立,则说明显示的TextureView和本身的位置是有90度的旋转的,所以需要交换宽高参数。
if (viewRotation == 90 || viewRotation == 270) {
int tempMeasureSpec = widthMeasureSpec;
widthMeasureSpec = heightMeasureSpec;
heightMeasureSpec = tempMeasureSpec;
}
int width = getDefaultSize(videoWidth, widthMeasureSpec);
int height = getDefaultSize(videoHeight, heightMeasureSpec);
if (videoWidth > 0 && videoHeight > 0) {
int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);
Log.i(TAG, "widthMeasureSpec [" + MeasureSpec.toString(widthMeasureSpec) + "]");
Log.i(TAG, "heightMeasureSpec [" + MeasureSpec.toString(heightMeasureSpec) + "]");
if (widthSpecMode == MeasureSpec.EXACTLY && heightSpecMode == MeasureSpec.EXACTLY) {
// the size is fixed
width = widthSpecSize;
height = heightSpecSize;
// for compatibility, we adjust size based on aspect ratio
if (videoWidth * height < width * videoHeight) {
width = height * videoWidth / videoHeight;
} else if (videoWidth * height > width * videoHeight) {
height = width * videoHeight / videoWidth;
}
} else if (widthSpecMode == MeasureSpec.EXACTLY) {
// only the width is fixed, adjust the height to match aspect ratio if possible
width = widthSpecSize;
height = width * videoHeight / videoWidth;
if (heightSpecMode == MeasureSpec.AT_MOST && height > heightSpecSize) {
// couldn't match aspect ratio within the constraints
height = heightSpecSize;
width = height * videoWidth / videoHeight;
}
} else if (heightSpecMode == MeasureSpec.EXACTLY) {
// only the height is fixed, adjust the width to match aspect ratio if possible
height = heightSpecSize;
width = height * videoWidth / videoHeight;
if (widthSpecMode == MeasureSpec.AT_MOST && width > widthSpecSize) {
// couldn't match aspect ratio within the constraints
width = widthSpecSize;
height = width * videoHeight / videoWidth;
}
} else {
// neither the width nor the height are fixed, try to use actual video size
width = videoWidth;
height = videoHeight;
if (heightSpecMode == MeasureSpec.AT_MOST && height > heightSpecSize) {
// too tall, decrease both width and height
height = heightSpecSize;
width = height * videoWidth / videoHeight;
}
if (widthSpecMode == MeasureSpec.AT_MOST && width > widthSpecSize) {
// too wide, decrease both width and height
width = widthSpecSize;
height = width * videoHeight / videoWidth;
}
}
} else {
// no size yet, just adopt the given spec sizes
}
setMeasuredDimension(width, height);
}
}
package fm.jiecao.jcvideoplayer_lib;
/**
* Created by Nathen
* On 2016/04/04 22:13
*/
public interface JCUserAction {
int ON_CLICK_START_ICON = 0;
int ON_CLICK_START_ERROR = 1;
int ON_CLICK_START_AUTO_COMPLETE = 2;
int ON_CLICK_PAUSE = 3;
int ON_CLICK_RESUME = 4;
int ON_SEEK_POSITION = 5;
int ON_AUTO_COMPLETE = 6;
int ON_ENTER_FULLSCREEN = 7;
int ON_QUIT_FULLSCREEN = 8;
int ON_ENTER_TINYSCREEN = 9;
int ON_QUIT_TINYSCREEN = 10;
int ON_TOUCH_SCREEN_SEEK_VOLUME = 11;
int ON_TOUCH_SCREEN_SEEK_POSITION = 12;
void onEvent(int type, String url, int screen, Object... objects);
}
package fm.jiecao.jcvideoplayer_lib;
/**
* Created by Nathen
* On 2016/04/26 20:53
*/
public interface JCUserActionStandard extends JCUserAction {
int ON_CLICK_START_THUMB = 101;
int ON_CLICK_BLANK = 102;
}
package fm.jiecao.jcvideoplayer_lib;
import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import java.util.Formatter;
import java.util.Locale;
/**
* Created by Nathen
* On 2016/02/21 12:25
*/
public class JCUtils {
public static String stringForTime(int timeMs) {
if (timeMs <= 0 || timeMs >= 24 * 60 * 60 * 1000) {
return "00:00";
}
int totalSeconds = timeMs / 1000;
int seconds = totalSeconds % 60;
int minutes = (totalSeconds / 60) % 60;
int hours = totalSeconds / 3600;
StringBuilder stringBuilder = new StringBuilder();
Formatter mFormatter = new Formatter(stringBuilder, Locale.getDefault());
if (hours > 0) {
return mFormatter.format("%d:%02d:%02d", hours, minutes, seconds).toString();
} else {
return mFormatter.format("%02d:%02d", minutes, seconds).toString();
}
}
/**
* This method requires the caller to hold the permission ACCESS_NETWORK_STATE.
*
* @param context a application context
* @return if wifi is connected,return true
*/
public static boolean isWifiConnected(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
return networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
}
/**
* Get activity from context object
*
* @param context something
* @return object of Activity or null if it is not Activity
*/
public static Activity scanForActivity(Context context) {
if (context == null)
return null;
if (context instanceof Activity) {
return (Activity) context;
} else if (context instanceof ContextWrapper) {
return scanForActivity(((ContextWrapper) context).getBaseContext());
}
return null;
}
/**
* Get AppCompatActivity from context
*
* @param context
* @return AppCompatActivity if it's not null
*/
public static AppCompatActivity getAppCompActivity(Context context) {
if (context == null)
return null;
if (context instanceof AppCompatActivity) {
return (AppCompatActivity) context;
}
return null;
}
public static int dip2px(Context context, float dpValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}
public static void saveProgress(Context context, String url, int progress) {
if (!JCVideoPlayer.SAVE_PROGRESS)
return;
SharedPreferences spn = context.getSharedPreferences("JCVD_PROGRESS",
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = spn.edit();
editor.putInt(url, progress);
editor.apply();
}
public static int getSavedProgress(Context context, String url) {
if (!JCVideoPlayer.SAVE_PROGRESS)
return 0;
SharedPreferences spn;
spn = context.getSharedPreferences("JCVD_PROGRESS",
Context.MODE_PRIVATE);
return spn.getInt(url, 0);
}
/**
* if url == null, clear all progress
*
* @param context
* @param url if url!=null clear this url progress
*/
public static void clearSavedProgress(Context context, String url) {
if (TextUtils.isEmpty(url)) {
SharedPreferences spn = context.getSharedPreferences("JCVD_PROGRESS",
Context.MODE_PRIVATE);
spn.edit().clear().apply();
} else {
SharedPreferences spn = context.getSharedPreferences("JCVD_PROGRESS",
Context.MODE_PRIVATE);
spn.edit().putInt(url, 0).apply();
}
}
}
package fm.jiecao.jcvideoplayer_lib;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Handler;
import android.provider.Settings;
import android.support.v7.app.ActionBar;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import org.greenrobot.eventbus.EventBus;
import java.lang.reflect.Constructor;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
/**
* Created by Nathen on 16/7/30.
*/
public abstract class JCVideoPlayer extends FrameLayout implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, View.OnTouchListener, View.OnLongClickListener {
public static final String TAG = "JieCaoVideoPlayer";
public static final int FULLSCREEN_ID = 33797;
public static final int TINY_ID = 33798;
public static final int THRESHOLD = 80;
public static final int FULL_SCREEN_NORMAL_DELAY = 300;
public static final int SCREEN_LAYOUT_NORMAL = 0;
public static final int SCREEN_LAYOUT_LIST = 1;
public static final int SCREEN_WINDOW_FULLSCREEN = 2;
public static final int SCREEN_WINDOW_TINY = 3;
public static final int CURRENT_STATE_NORMAL = 0;
public static final int CURRENT_STATE_PREPARING = 1;
public static final int CURRENT_STATE_PLAYING = 2;
public static final int CURRENT_STATE_PLAYING_BUFFERING_START = 3;
public static final int CURRENT_STATE_PAUSE = 5;
public static final int CURRENT_STATE_AUTO_COMPLETE = 6;
public static final int CURRENT_STATE_ERROR = 7;
public static boolean ACTION_BAR_EXIST = true;
public static boolean TOOL_BAR_EXIST = true;
public static int FULLSCREEN_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_SENSOR;
public static int NORMAL_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
public static boolean SAVE_PROGRESS = true;
public static boolean WIFI_TIP_DIALOG_SHOWED = false;
public static long CLICK_QUIT_FULLSCREEN_TIME = 0;
public static int BACKUP_PLAYING_BUFFERING_STATE = -1;
public static boolean noAction = false;
public static long lastAutoFullscreenTime = 0;
public static AudioManager.OnAudioFocusChangeListener onAudioFocusChangeListener = new AudioManager.OnAudioFocusChangeListener() {
@Override
public void onAudioFocusChange(int focusChange) {
switch (focusChange) {
case AudioManager.AUDIOFOCUS_GAIN:
break;
case AudioManager.AUDIOFOCUS_LOSS:
releaseAllVideos();
Log.d(TAG, "AUDIOFOCUS_LOSS [" + this.hashCode() + "]");
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
try {
if (JCMediaManager.instance().mediaPlayer != null &&
JCMediaManager.instance().mediaPlayer.isPlaying()) {
JCMediaManager.instance().mediaPlayer.pause();
}
} catch (IllegalStateException e) {
e.printStackTrace();
}
Log.d(TAG, "AUDIOFOCUS_LOSS_TRANSIENT [" + this.hashCode() + "]");
break;
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
break;
}
}
};
protected static JCUserAction JC_USER_EVENT;
protected static Timer UPDATE_PROGRESS_TIMER;
public int currentState = -1;
public int currentScreen = -1;
public boolean loop = false;
public Map<String, String> headData;
public String url = "";
public Object[] objects = null;
public int seekToInAdvance = 0;
public ImageView startButton;
public ImageView gotoanother;
public SeekBar progressBar;
public ImageView fullscreenButton;
public TextView currentTimeTextView, totalTimeTextView;
public ViewGroup textureViewContainer;
public ViewGroup topContainer, bottomContainer;
public int widthRatio = 1;
public int heightRatio = 1;
public JVOnClicklistener mListener = new JVOnClicklistener() {
@Override
public void onClick() {
Log.i("JieCaoVideoPlayer", "onClick: JVOnClicklistener");
}
@Override
public void onLongClick() {
Log.i("JieCaoVideoPlayer", "onLongClick: JVOnClicklistener");
}
};
protected int mScreenWidth;
protected int mScreenHeight;
protected AudioManager mAudioManager;
protected Handler mHandler;
protected ProgressTimerTask mProgressTimerTask;
protected boolean mTouchingProgressBar;
protected float mDownX;
protected float mDownY;
protected boolean mChangeVolume;
protected boolean mChangePosition;
protected boolean mChangeBrightness;
protected int mGestureDownPosition;
protected int mGestureDownVolume;
protected float mGestureDownBrightness;
protected int mSeekTimePosition;
private ImageView thumb;
public JCVideoPlayer(Context context) {
super(context);
init(context);
}
public JCVideoPlayer(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public static boolean backPress() {
if ((System.currentTimeMillis() - CLICK_QUIT_FULLSCREEN_TIME) < FULL_SCREEN_NORMAL_DELAY)
return false;
if (JCVideoPlayerManager.getSecondFloor() != null) {
CLICK_QUIT_FULLSCREEN_TIME = System.currentTimeMillis();
JCVideoPlayer jcVideoPlayer = JCVideoPlayerManager.getSecondFloor();
jcVideoPlayer.onEvent(jcVideoPlayer.currentScreen == JCVideoPlayerStandard.SCREEN_WINDOW_FULLSCREEN ?
JCUserAction.ON_QUIT_FULLSCREEN : JCUserAction.ON_QUIT_TINYSCREEN);
JCVideoPlayerManager.getFirstFloor().playOnThisJcvd();
return true;
} else if (JCVideoPlayerManager.getFirstFloor() != null &&
(JCVideoPlayerManager.getFirstFloor().currentScreen == SCREEN_WINDOW_FULLSCREEN ||
JCVideoPlayerManager.getFirstFloor().currentScreen == SCREEN_WINDOW_TINY)) { // 以前我总想把这两个判断写到一起,这分明是两个独立是逻辑
CLICK_QUIT_FULLSCREEN_TIME = System.currentTimeMillis();
// 直接退出全屏和小窗
JCVideoPlayerManager.getCurrentJcvd().currentState = CURRENT_STATE_NORMAL;
JCVideoPlayerManager.getFirstFloor().clearFloatScreen();
JCMediaManager.instance().releaseMediaPlayer();
JCVideoPlayerManager.setFirstFloor(null);
return true;
}
return false;
}
public static void releaseAllVideos() {
if ((System.currentTimeMillis() - CLICK_QUIT_FULLSCREEN_TIME) > FULL_SCREEN_NORMAL_DELAY) {
JCVideoPlayerManager.completeAll();
JCMediaManager.instance().releaseMediaPlayer();
}
}
public static void setJcUserAction(JCUserAction jcUserEvent) {
JC_USER_EVENT = jcUserEvent;
}
public static void startFullscreen(Context context, Class _class, String url, Object... objects) {
hideSupportActionBar(context);
JCUtils.getAppCompActivity(context).setRequestedOrientation(FULLSCREEN_ORIENTATION);
ViewGroup vp = (ViewGroup) (JCUtils.scanForActivity(context))//.getWindow().getDecorView();
.findViewById(Window.ID_ANDROID_CONTENT);
View old = vp.findViewById(JCVideoPlayer.FULLSCREEN_ID);
if (old != null) {
vp.removeView(old);
}
try {
Constructor<JCVideoPlayer> constructor = _class.getConstructor(Context.class);
final JCVideoPlayer jcVideoPlayer = constructor.newInstance(context);
jcVideoPlayer.setId(JCVideoPlayer.FULLSCREEN_ID);
LayoutParams lp = new LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
vp.addView(jcVideoPlayer, lp);
jcVideoPlayer.setUp(url, JCVideoPlayerStandard.SCREEN_WINDOW_FULLSCREEN, objects);
CLICK_QUIT_FULLSCREEN_TIME = System.currentTimeMillis();
jcVideoPlayer.startButton.performClick();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void hideSupportActionBar(Context context) {
if (noAction) {
return;
}
if (ACTION_BAR_EXIST) {
ActionBar ab = JCUtils.getAppCompActivity(context).getSupportActionBar();
if (ab != null) {
ab.setShowHideAnimationEnabled(false);
ab.hide();
}
}
if (TOOL_BAR_EXIST) {
JCUtils.getAppCompActivity(context).getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
public static void showSupportActionBar(Context context) {
if (noAction) {
return;
}
if (ACTION_BAR_EXIST) {
ActionBar ab = JCUtils.getAppCompActivity(context).getSupportActionBar();
if (ab != null) {
ab.setShowHideAnimationEnabled(false);
ab.show();
}
}
if (TOOL_BAR_EXIST) {
JCUtils.getAppCompActivity(context).getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
public static void clearSavedProgress(Context context, String url) {
JCUtils.clearSavedProgress(context, url);
}
public void setUp(String url, int screen, Object... objects) {
if (!TextUtils.isEmpty(this.url) && TextUtils.equals(this.url, url)) {
return;
}
this.url = url;
this.objects = objects;
this.currentScreen = screen;
this.headData = null;
setUiWitStateAndScreen(CURRENT_STATE_NORMAL);
}
public void init(Context context) {
View.inflate(context, getLayoutId(), this);
startButton = (ImageView) findViewById(R.id.start);
gotoanother = (ImageView) findViewById(R.id.gotoanother);
fullscreenButton = (ImageView) findViewById(R.id.fullscreen);
progressBar = (SeekBar) findViewById(R.id.bottom_seek_progress);
currentTimeTextView = (TextView) findViewById(R.id.current);
totalTimeTextView = (TextView) findViewById(R.id.total);
bottomContainer = (ViewGroup) findViewById(R.id.layout_bottom);
textureViewContainer = (ViewGroup) findViewById(R.id.surface_container);
topContainer = (ViewGroup) findViewById(R.id.layout_top);
startButton.setOnClickListener(this);
gotoanother.setOnClickListener(this);
fullscreenButton.setOnClickListener(this);
progressBar.setOnSeekBarChangeListener(this);
bottomContainer.setOnClickListener(this);
textureViewContainer.setOnClickListener(this);
textureViewContainer.setOnTouchListener(this);
mScreenWidth = getContext().getResources().getDisplayMetrics().widthPixels;
mScreenHeight = getContext().getResources().getDisplayMetrics().heightPixels;
mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
mHandler = new Handler();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (currentScreen == SCREEN_WINDOW_FULLSCREEN || currentScreen == SCREEN_WINDOW_TINY) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
return;
}
if (widthRatio != 0 && heightRatio != 0) {
int specWidth = MeasureSpec.getSize(widthMeasureSpec);
int specHeight = (int) ((specWidth * (float) heightRatio) / widthRatio);
setMeasuredDimension(specWidth, specHeight);
int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(specWidth, MeasureSpec.EXACTLY);
int childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(specHeight, MeasureSpec.EXACTLY);
getChildAt(0).measure(childWidthMeasureSpec, childHeightMeasureSpec);
} else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
@Override
public boolean onTouch(View v, MotionEvent event) {
float x = event.getX();
float y = event.getY();
int id = v.getId();
if (id == R.id.surface_container) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
Log.i(TAG, "onTouch surfaceContainer actionDown [" + this.hashCode() + "] ");
mTouchingProgressBar = true;
mDownX = x;
mDownY = y;
mChangeVolume = false;
mChangePosition = false;
mChangeBrightness = false;
break;
case MotionEvent.ACTION_MOVE:
Log.i(TAG, "onTouch surfaceContainer actionMove [" + this.hashCode() + "] ");
float deltaX = x - mDownX;
float deltaY = y - mDownY;
float absDeltaX = Math.abs(deltaX);
float absDeltaY = Math.abs(deltaY);
if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
if (!mChangePosition && !mChangeVolume && !mChangeBrightness) {
if (absDeltaX > THRESHOLD || absDeltaY > THRESHOLD) {
cancelProgressTimer();
if (absDeltaX >= THRESHOLD) {
// 全屏模式下的CURRENT_STATE_ERROR状态下,不响应进度拖动事件.
// 否则会因为mediaplayer的状态非法导致App Crash
if (currentState != CURRENT_STATE_ERROR) {
mChangePosition = true;
mGestureDownPosition = getCurrentPositionWhenPlaying();
}
} else {
//如果y轴滑动距离超过设置的处理范围,那么进行滑动事件处理
if (mDownX < mScreenWidth * 0.5f) {//左侧改变亮度
mChangeBrightness = true;
try {
mGestureDownBrightness = Settings.System.getInt(getContext().getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
System.out.println("当前亮度 " + mGestureDownBrightness);
} catch (Settings.SettingNotFoundException e) {
e.printStackTrace();
}
} else {//右侧改变声音
mChangeVolume = true;
mGestureDownVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
}
}
}
}
}
if (mChangePosition) {
int totalTimeDuration = getDuration();
mSeekTimePosition = (int) (mGestureDownPosition + deltaX * totalTimeDuration / mScreenWidth);
if (mSeekTimePosition > totalTimeDuration)
mSeekTimePosition = totalTimeDuration;
String seekTime = JCUtils.stringForTime(mSeekTimePosition);
String totalTime = JCUtils.stringForTime(totalTimeDuration);
showProgressDialog(deltaX, seekTime, mSeekTimePosition, totalTime, totalTimeDuration);
}
if (mChangeVolume) {
deltaY = -deltaY;
int max = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int deltaV = (int) (max * deltaY * 3 / mScreenHeight);
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mGestureDownVolume + deltaV, 0);
// dialog中显示百分比
int volumePercent = (int) (mGestureDownVolume * 100 / max + deltaY * 3 * 100 / mScreenHeight);
showVolumeDialog(-deltaY, volumePercent);
}
if (mChangeBrightness) {
deltaY = -deltaY;
int deltaV = (int) (255 * deltaY * 3 / mScreenHeight);
WindowManager.LayoutParams params = JCUtils.getAppCompActivity(getContext()).getWindow().getAttributes();
if (((mGestureDownBrightness + deltaV) / 255) >= 1) {//这和声音有区别,必须自己过滤一下负值
params.screenBrightness = 1;
} else if (((mGestureDownBrightness + deltaV) / 255) <= 0) {
params.screenBrightness = 0.01f;
} else {
params.screenBrightness = (mGestureDownBrightness + deltaV) / 255;
}
JCUtils.getAppCompActivity(getContext()).getWindow().setAttributes(params);
// dialog中显示百分比
int brightnessPercent = (int) (mGestureDownBrightness * 100 / 255 + deltaY * 3 * 100 / mScreenHeight);
System.out.println("percentfdsfdsf : " + brightnessPercent + " " + deltaY + " " + mGestureDownBrightness);
showBrightnessDialog(brightnessPercent);
// mDownY = y;
}
break;
case MotionEvent.ACTION_UP:
Log.i(TAG, "onTouch surfaceContainer actionUp [" + this.hashCode() + "] ");
mTouchingProgressBar = false;
dismissProgressDialog();
dismissVolumeDialog();
dismissBrightnessDialog();
if (mChangePosition) {
onEvent(JCUserAction.ON_TOUCH_SCREEN_SEEK_POSITION);
JCMediaManager.instance().mediaPlayer.seekTo(mSeekTimePosition);
int duration = getDuration();
int progress = mSeekTimePosition * 100 / (duration == 0 ? 1 : duration);
progressBar.setProgress(progress);
}
if (mChangeVolume) {
onEvent(JCUserAction.ON_TOUCH_SCREEN_SEEK_VOLUME);
}
startProgressTimer();
break;
}
}
return false;
}
@Override
public void onClick(View v) {
int i = v.getId();
if (i == R.id.start) {
Log.i(TAG, "onClick start [" + this.hashCode() + "] ");
if (TextUtils.isEmpty(url)) {
Toast.makeText(getContext(), getResources().getString(R.string.no_url), Toast.LENGTH_SHORT).show();
return;
}
if (mListener != null) {
Log.e("xuan", "JCVideoOnClick: ");
mListener.onClick();
}
if (currentState == CURRENT_STATE_NORMAL || currentState == CURRENT_STATE_ERROR) {
if (!url.startsWith("file") && !JCUtils.isWifiConnected(getContext()) && !WIFI_TIP_DIALOG_SHOWED) {
showWifiDialog();
return;
}
prepareMediaPlayer();
onEvent(currentState != CURRENT_STATE_ERROR ? JCUserAction.ON_CLICK_START_ICON : JCUserAction.ON_CLICK_START_ERROR);
} else if (currentState == CURRENT_STATE_PLAYING) {
onEvent(JCUserAction.ON_CLICK_PAUSE);
Log.d(TAG, "pauseVideo [" + this.hashCode() + "] ");
JCMediaManager.instance().mediaPlayer.pause();
setUiWitStateAndScreen(CURRENT_STATE_PAUSE);
} else if (currentState == CURRENT_STATE_PAUSE) {
onEvent(JCUserAction.ON_CLICK_RESUME);
JCMediaManager.instance().mediaPlayer.start();
setUiWitStateAndScreen(CURRENT_STATE_PLAYING);
} else if (currentState == CURRENT_STATE_AUTO_COMPLETE) {
onEvent(JCUserAction.ON_CLICK_START_AUTO_COMPLETE);
prepareMediaPlayer();
}
} else if (i == R.id.fullscreen) {
Log.i(TAG, "onClick fullscreen [" + this.hashCode() + "] ");
if (currentState == CURRENT_STATE_AUTO_COMPLETE)
return;
if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
//quit fullscreen
backPress();
} else {
Log.d(TAG, "toFullscreenActivity [" + this.hashCode() + "] ");
onEvent(JCUserAction.ON_ENTER_FULLSCREEN);
startWindowFullscreen();
}
} else if (i == R.id.surface_container && currentState == CURRENT_STATE_ERROR) {
Log.i(TAG, "onClick surfaceContainer State=Error [" + this.hashCode() + "] ");
prepareMediaPlayer();
} else if (i == R.id.gotoanother) {
}
}
@Override
public boolean onLongClick(View v) {
if (mListener != null)
mListener.onLongClick();
return true;
}
public void initTextureView() {
removeTextureView();
JCMediaManager.textureView = new JCResizeTextureView(getContext());
JCMediaManager.textureView.setSurfaceTextureListener(JCMediaManager.instance());
}
public void addTextureView() {
Log.d(TAG, "addTextureView [" + this.hashCode() + "] ");
LayoutParams layoutParams =
new LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
Gravity.CENTER);
textureViewContainer.addView(JCMediaManager.textureView, layoutParams);
}
public void removeTextureView() {
JCMediaManager.savedSurfaceTexture = null;
if (JCMediaManager.textureView != null && JCMediaManager.textureView.getParent() != null) {
((ViewGroup) JCMediaManager.textureView.getParent()).removeView(JCMediaManager.textureView);
}
}
public void setUiWitStateAndScreen(int state) {
currentState = state;
switch (currentState) {
case CURRENT_STATE_NORMAL:
cancelProgressTimer();
if (isCurrentJcvd()) {//这个if是无法取代的,否则进入全屏的时候会releaseMediaPlayer
JCMediaManager.instance().releaseMediaPlayer();
}
break;
case CURRENT_STATE_PREPARING:
resetProgressAndTime();
break;
case CURRENT_STATE_PLAYING:
case CURRENT_STATE_PAUSE:
case CURRENT_STATE_PLAYING_BUFFERING_START:
startProgressTimer();
break;
case CURRENT_STATE_ERROR:
cancelProgressTimer();
break;
case CURRENT_STATE_AUTO_COMPLETE:
cancelProgressTimer();
progressBar.setProgress(100);
currentTimeTextView.setText(totalTimeTextView.getText());
break;
}
}
public void startProgressTimer() {
cancelProgressTimer();
UPDATE_PROGRESS_TIMER = new Timer();
mProgressTimerTask = new ProgressTimerTask();
UPDATE_PROGRESS_TIMER.schedule(mProgressTimerTask, 0, 300);
}
public void cancelProgressTimer() {
if (UPDATE_PROGRESS_TIMER != null) {
UPDATE_PROGRESS_TIMER.cancel();
}
if (mProgressTimerTask != null) {
mProgressTimerTask.cancel();
}
}
public void onPrepared() {
Log.i(TAG, "onPrepared " + " [" + this.hashCode() + "] ");
if (currentState != CURRENT_STATE_PREPARING)
return;
if (seekToInAdvance != 0) {
JCMediaManager.instance().mediaPlayer.seekTo(seekToInAdvance);
seekToInAdvance = 0;
} else {
int position = JCUtils.getSavedProgress(getContext(), url);
if (position != 0) {
JCMediaManager.instance().mediaPlayer.seekTo(position);
}
}
startProgressTimer();
setUiWitStateAndScreen(CURRENT_STATE_PLAYING);
}
public void clearFullscreenLayout() {
ViewGroup vp = (ViewGroup) (JCUtils.scanForActivity(getContext()))//.getWindow().getDecorView();
.findViewById(Window.ID_ANDROID_CONTENT);
View oldF = vp.findViewById(FULLSCREEN_ID);
View oldT = vp.findViewById(TINY_ID);
if (oldF != null) {
vp.removeView(oldF);
}
if (oldT != null) {
vp.removeView(oldT);
}
// 现所有界面都不是ActionBar,而为自定义的title,不显示,以免覆盖了title
/*showSupportActionBar(getContext());*/
}
public void onAutoCompletion() {
// 加上这句,避免循环播放video的时候,内存不断飙升。
Runtime.getRuntime().gc();
Log.i(TAG, "onAutoCompletion " + " [" + this.hashCode() + "] ");
onEvent(JCUserAction.ON_AUTO_COMPLETE);
dismissVolumeDialog();
dismissProgressDialog();
dismissBrightnessDialog();
cancelProgressTimer();
setUiWitStateAndScreen(CURRENT_STATE_AUTO_COMPLETE);
if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
backPress();
}
JCUtils.saveProgress(getContext(), url, 0);
}
public void onCompletion() {
Log.i(TAG, "onCompletion " + " [" + this.hashCode() + "] ");
// Save position
if (currentState == CURRENT_STATE_PLAYING || currentState == CURRENT_STATE_PAUSE) {
int position = getCurrentPositionWhenPlaying();
JCUtils.saveProgress(getContext(), url, position);
}
cancelProgressTimer();
setUiWitStateAndScreen(CURRENT_STATE_NORMAL);
// 清理缓存变量
textureViewContainer.removeView(JCMediaManager.textureView);
JCMediaManager.instance().currentVideoWidth = 0;
JCMediaManager.instance().currentVideoHeight = 0;
AudioManager mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
mAudioManager.abandonAudioFocus(onAudioFocusChangeListener);
JCUtils.scanForActivity(getContext()).getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
clearFullscreenLayout();
JCUtils.getAppCompActivity(getContext()).setRequestedOrientation(NORMAL_ORIENTATION);
JCMediaManager.textureView = null;
JCMediaManager.savedSurfaceTexture = null;
// JCMediaManager.textureView = null;
}
// 退出全屏和小窗的方法
public void playOnThisJcvd() {
Log.i(TAG, "playOnThisJcvd " + " [" + this.hashCode() + "] ");
//1.清空全屏和小窗的jcvd
currentState = JCVideoPlayerManager.getSecondFloor().currentState;
clearFloatScreen();
//2.在本jcvd上播放
setUiWitStateAndScreen(currentState);
addTextureView();
}
public void clearFloatScreen() {
JCUtils.getAppCompActivity(getContext()).setRequestedOrientation(NORMAL_ORIENTATION);
// 现所有界面都不是ActionBar,而为自定义的title,不显示,以免覆盖了title
/*showSupportActionBar(getContext());*/
JCVideoPlayer secJcvd = JCVideoPlayerManager.getCurrentJcvd();
secJcvd.textureViewContainer.removeView(JCMediaManager.textureView);
ViewGroup vp = (ViewGroup) (JCUtils.scanForActivity(getContext()))//.getWindow().getDecorView();
.findViewById(Window.ID_ANDROID_CONTENT);
vp.removeView(secJcvd);
JCVideoPlayerManager.setSecondFloor(null);
}
// 重力感应的时候调用的函数,
public void autoFullscreen(float x) {
if (isCurrentJcvd()
&& currentState == CURRENT_STATE_PLAYING
&& currentScreen != SCREEN_WINDOW_FULLSCREEN
&& currentScreen != SCREEN_WINDOW_TINY) {
if (x > 0) {
JCUtils.getAppCompActivity(getContext()).setRequestedOrientation(
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
JCUtils.getAppCompActivity(getContext()).setRequestedOrientation(
ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
}
startWindowFullscreen();
}
}
public void autoQuitFullscreen() {
if ((System.currentTimeMillis() - lastAutoFullscreenTime) > 2000
&& isCurrentJcvd()
&& currentState == CURRENT_STATE_PLAYING
&& currentScreen == SCREEN_WINDOW_FULLSCREEN) {
lastAutoFullscreenTime = System.currentTimeMillis();
backPress();
}
}
public void onSeekComplete() {
}
public void onError(int what, int extra) {
Log.e(TAG, "onError " + what + " - " + extra + " [" + this.hashCode() + "] ");
if (what != 38 && what != -38) {
setUiWitStateAndScreen(CURRENT_STATE_ERROR);
if (isCurrentJcvd()) {
JCMediaManager.instance().releaseMediaPlayer();
}
}
}
public void onInfo(int what, int extra) {
Log.d(TAG, "onInfo what - " + what + " extra - " + extra);
if (what == MediaPlayer.MEDIA_INFO_BUFFERING_START) {
if (currentState == CURRENT_STATE_PLAYING_BUFFERING_START)
return;
BACKUP_PLAYING_BUFFERING_STATE = currentState;
setUiWitStateAndScreen(CURRENT_STATE_PLAYING_BUFFERING_START);//没这个case
Log.d(TAG, "MEDIA_INFO_BUFFERING_START");
} else if (what == MediaPlayer.MEDIA_INFO_BUFFERING_END) {
if (BACKUP_PLAYING_BUFFERING_STATE != -1) {
setUiWitStateAndScreen(BACKUP_PLAYING_BUFFERING_STATE);
BACKUP_PLAYING_BUFFERING_STATE = -1;
}
Log.d(TAG, "MEDIA_INFO_BUFFERING_END");
}
}
public void onVideoSizeChanged() {
Log.i(TAG, "onVideoSizeChanged " + " [" + this.hashCode() + "] ");
JCMediaManager.textureView.setVideoSize(JCMediaManager.instance().getVideoSize());
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
Log.i(TAG, "bottomProgress onStartTrackingTouch [" + this.hashCode() + "] ");
cancelProgressTimer();
ViewParent vpdown = getParent();
while (vpdown != null) {
vpdown.requestDisallowInterceptTouchEvent(true);
vpdown = vpdown.getParent();
}
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
Log.i(TAG, "bottomProgress onStopTrackingTouch [" + this.hashCode() + "] ");
onEvent(JCUserAction.ON_SEEK_POSITION);
startProgressTimer();
ViewParent vpup = getParent();
while (vpup != null) {
vpup.requestDisallowInterceptTouchEvent(false);
vpup = vpup.getParent();
}
if (currentState != CURRENT_STATE_PLAYING &&
currentState != CURRENT_STATE_PAUSE)
return;
int time = seekBar.getProgress() * getDuration() / 100;
JCMediaManager.instance().mediaPlayer.seekTo(time);
Log.i(TAG, "seekTo " + time + " [" + this.hashCode() + "] ");
}
public void prepareMediaPlayer() {
EventBus.getDefault().post(new MessageEvent("prepare"));
JCVideoPlayerManager.completeAll();
Log.d(TAG, "prepareMediaPlayer [" + this.hashCode() + "] ");
initTextureView();
addTextureView();
AudioManager mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
mAudioManager.requestAudioFocus(onAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
// 当播放时才有焦点
JCUtils.scanForActivity(getContext()).getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
JCMediaManager.CURRENT_PLAYING_URL = url;
JCMediaManager.CURRENT_PLING_LOOP = loop;
JCMediaManager.MAP_HEADER_DATA = headData;
setUiWitStateAndScreen(CURRENT_STATE_PREPARING);
JCVideoPlayerManager.setFirstFloor(this);
// 直接跳转至全屏播放
startWindowFullscreen();
}
public boolean startWindowFullscreen() {
Log.i(TAG, "startWindowFullscreen " + " [" + this.hashCode() + "] ");
// hideSupportActionBar(getContext());
JCUtils.getAppCompActivity(getContext()).setRequestedOrientation(FULLSCREEN_ORIENTATION);
ViewGroup vp = (ViewGroup) (JCUtils.scanForActivity(getContext()))//.getWindow().getDecorView();
.findViewById(Window.ID_ANDROID_CONTENT);
View old = vp.findViewById(FULLSCREEN_ID);
if (old != null) {
vp.removeView(old);
}
textureViewContainer.removeView(JCMediaManager.textureView);
try {
Constructor<JCVideoPlayer> constructor = (Constructor<JCVideoPlayer>) JCVideoPlayer.this.getClass().getConstructor(Context.class);
JCVideoPlayer jcVideoPlayer = constructor.newInstance(getContext());
jcVideoPlayer.setId(FULLSCREEN_ID);
jcVideoPlayer.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Log.e("zx", "onLongClick: ");
return false;
}
});
LayoutParams lp = new LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
vp.addView(jcVideoPlayer, lp);
jcVideoPlayer.setUp(url, JCVideoPlayerStandard.SCREEN_WINDOW_FULLSCREEN, objects);
jcVideoPlayer.setUiWitStateAndScreen(currentState);
jcVideoPlayer.addTextureView();
JCVideoPlayerManager.setSecondFloor(jcVideoPlayer);
CLICK_QUIT_FULLSCREEN_TIME = System.currentTimeMillis();
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
public void startWindowTiny() {
Log.i(TAG, "startWindowTiny " + " [" + this.hashCode() + "] ");
onEvent(JCUserAction.ON_ENTER_TINYSCREEN);
if (currentState == CURRENT_STATE_NORMAL || currentState == CURRENT_STATE_ERROR)
return;
ViewGroup vp = (ViewGroup) (JCUtils.scanForActivity(getContext()))//.getWindow().getDecorView();
.findViewById(Window.ID_ANDROID_CONTENT);
View old = vp.findViewById(TINY_ID);
if (old != null) {
vp.removeView(old);
}
textureViewContainer.removeView(JCMediaManager.textureView);
try {
Constructor<JCVideoPlayer> constructor = (Constructor<JCVideoPlayer>) JCVideoPlayer.this.getClass().getConstructor(Context.class);
JCVideoPlayer jcVideoPlayer = constructor.newInstance(getContext());
jcVideoPlayer.setId(TINY_ID);
LayoutParams lp = new LayoutParams(400, 400);
lp.gravity = Gravity.RIGHT | Gravity.BOTTOM;
vp.addView(jcVideoPlayer, lp);
jcVideoPlayer.setUp(url, JCVideoPlayerStandard.SCREEN_WINDOW_TINY, objects);
jcVideoPlayer.setUiWitStateAndScreen(currentState);
jcVideoPlayer.addTextureView();
JCVideoPlayerManager.setSecondFloor(jcVideoPlayer);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
public int getCurrentPositionWhenPlaying() {
int position = 0;
if (currentState == CURRENT_STATE_PLAYING ||
currentState == CURRENT_STATE_PAUSE ||
currentState == CURRENT_STATE_PLAYING_BUFFERING_START) {
try {
position = JCMediaManager.instance().mediaPlayer.getCurrentPosition();
} catch (IllegalStateException e) {
e.printStackTrace();
return position;
}
}
return position;
}
public int getDuration() {
int duration = 0;
try {
duration = JCMediaManager.instance().mediaPlayer.getDuration();
} catch (IllegalStateException e) {
e.printStackTrace();
return duration;
}
return duration;
}
public void setProgressAndText() {
int position = getCurrentPositionWhenPlaying();
int duration = getDuration();
int progress = position * 100 / (duration == 0 ? 1 : duration);
if (!mTouchingProgressBar) {
if (progress != 0)
progressBar.setProgress(progress);
}
if (position != 0)
currentTimeTextView.setText(JCUtils.stringForTime(position));
totalTimeTextView.setText(JCUtils.stringForTime(duration));
}
public void setBufferProgress(int bufferProgress) {
if (bufferProgress != 0)
progressBar.setSecondaryProgress(bufferProgress);
}
public void resetProgressAndTime() {
progressBar.setProgress(0);
progressBar.setSecondaryProgress(0);
currentTimeTextView.setText(JCUtils.stringForTime(0));
totalTimeTextView.setText(JCUtils.stringForTime(0));
}
public void release() {
if (url.equals(JCMediaManager.CURRENT_PLAYING_URL) &&
(System.currentTimeMillis() - CLICK_QUIT_FULLSCREEN_TIME) > FULL_SCREEN_NORMAL_DELAY) {
// 在非全屏的情况下只能backPress()
if (JCVideoPlayerManager.getSecondFloor() != null &&
JCVideoPlayerManager.getSecondFloor().currentScreen == SCREEN_WINDOW_FULLSCREEN) {//点击全屏
} else if (JCVideoPlayerManager.getSecondFloor() == null && JCVideoPlayerManager.getFirstFloor() != null &&
JCVideoPlayerManager.getFirstFloor().currentScreen == SCREEN_WINDOW_FULLSCREEN) {//直接全屏
} else {
Log.d(TAG, "release [" + this.hashCode() + "]");
releaseAllVideos();
}
}
}
//isCurrentJcvd and isCurrenPlayUrl should be two logic methods,isCurrentJcvd is for different jcvd with same
//url when fullscreen or tiny screen. isCurrenPlayUrl is to find where is myself when back from tiny screen.
//Sometimes they are overlap.
public boolean isCurrentJcvd() {//虽然看这个函数很不爽,但是干不掉
return JCVideoPlayerManager.getCurrentJcvd() != null
&& JCVideoPlayerManager.getCurrentJcvd() == this;
}
public void onEvent(int type) {
if (JC_USER_EVENT != null && isCurrentJcvd()) {
JC_USER_EVENT.onEvent(type, url, currentScreen, objects);
}
}
public void addChatClicklistener(JVOnClicklistener listener) {
mListener = listener;
}
public void showWifiDialog() {
}
public void showProgressDialog(float deltaX,
String seekTime, int seekTimePosition,
String totalTime, int totalTimeDuration) {
}
public void dismissProgressDialog() {
}
public void showVolumeDialog(float deltaY, int volumePercent) {
}
public void dismissVolumeDialog() {
}
public void showBrightnessDialog(int brightnessPercent) {
}
public void dismissBrightnessDialog() {
}
public abstract int getLayoutId();
public interface JVOnClicklistener {
void onClick();
void onLongClick();
}
public static class JCAutoFullscreenListener implements SensorEventListener {
@Override
public void onSensorChanged(SensorEvent event) {//可以得到传感器实时测量出来的变化值
final float x = event.values[SensorManager.DATA_X];
float y = event.values[SensorManager.DATA_Y];
float z = event.values[SensorManager.DATA_Z];
// 过滤掉用力过猛会有一个反向的大数值
if (((x > -15 && x < -10) || (x < 15 && x > 10)) && Math.abs(y) < 1.5) {
if ((System.currentTimeMillis() - lastAutoFullscreenTime) > 2000) {
if (JCVideoPlayerManager.getCurrentJcvd() != null) {
JCVideoPlayerManager.getCurrentJcvd().autoFullscreen(x);
}
lastAutoFullscreenTime = System.currentTimeMillis();
}
}
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}
public class ProgressTimerTask extends TimerTask {
@Override
public void run() {
if (currentState == CURRENT_STATE_PLAYING || currentState == CURRENT_STATE_PAUSE || currentState == CURRENT_STATE_PLAYING_BUFFERING_START) {
// Log.v(TAG, "onProgressUpdate " + position + "/" + duration + " [" + this.hashCode() + "] ");
mHandler.post(
new Runnable() {
@Override
public void run() {
setProgressAndText();
}
});
}
}
}
}
package fm.jiecao.jcvideoplayer_lib;
/**
* Put JCVideoPlayer into layout
* From a JCVideoPlayer to another JCVideoPlayer
* Created by Nathen on 16/7/26.
*/
public class JCVideoPlayerManager {
public static JCVideoPlayer FIRST_FLOOR_JCVD;
public static JCVideoPlayer SECOND_FLOOR_JCVD;
public static void setFirstFloor(JCVideoPlayer jcVideoPlayer) {
FIRST_FLOOR_JCVD = jcVideoPlayer;
}
public static void setSecondFloor(JCVideoPlayer jcVideoPlayer) {
SECOND_FLOOR_JCVD = jcVideoPlayer;
}
public static JCVideoPlayer getFirstFloor() {
return FIRST_FLOOR_JCVD;
}
public static JCVideoPlayer getSecondFloor() {
return SECOND_FLOOR_JCVD;
}
public static JCVideoPlayer getCurrentJcvd() {
if (getSecondFloor() != null) {
return getSecondFloor();
}
return getFirstFloor();
}
public static void completeAll() {
if (SECOND_FLOOR_JCVD != null) {
SECOND_FLOOR_JCVD.onCompletion();
SECOND_FLOOR_JCVD = null;
}
if (FIRST_FLOOR_JCVD != null) {
FIRST_FLOOR_JCVD.onCompletion();
FIRST_FLOOR_JCVD = null;
}
}
}
package fm.jiecao.jcvideoplayer_lib;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.SeekBar;
import android.widget.Toast;
/**
* Manage UI
* Created by Nathen
* On 2016/04/10 15:45
*/
public class JCVideoPlayerSimple extends JCVideoPlayer {
public JCVideoPlayerSimple(Context context) {
super(context);
}
public JCVideoPlayerSimple(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public int getLayoutId() {
return R.layout.jc_layout_base;
}
@Override
public void setUp(String url, int screen, Object... objects) {
super.setUp(url, screen, objects);
updateFullscreenButton();
fullscreenButton.setVisibility(View.GONE);
}
@Override
public void setUiWitStateAndScreen(int state) {
super.setUiWitStateAndScreen(state);
switch (currentState) {
case CURRENT_STATE_NORMAL:
startButton.setVisibility(View.VISIBLE);
break;
case CURRENT_STATE_PREPARING:
startButton.setVisibility(View.INVISIBLE);
break;
case CURRENT_STATE_PLAYING:
startButton.setVisibility(View.VISIBLE);
break;
case CURRENT_STATE_PAUSE:
break;
case CURRENT_STATE_ERROR:
break;
}
updateStartImage();
}
private void updateStartImage() {
if (currentState == CURRENT_STATE_PLAYING) {
startButton.setImageResource(R.drawable.jc_click_pause_selector);
} else if (currentState == CURRENT_STATE_ERROR) {
startButton.setImageResource(R.drawable.jc_click_error_selector);
} else {
startButton.setImageResource(R.drawable.jc_click_play_selector);
}
}
public void updateFullscreenButton() {
if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
fullscreenButton.setImageResource(R.drawable.jc_shrink);
} else {
fullscreenButton.setImageResource(R.drawable.jc_enlarge);
}
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.fullscreen && currentState == CURRENT_STATE_NORMAL) {
Toast.makeText(getContext(), "Play video first", Toast.LENGTH_SHORT).show();
return;
}
super.onClick(v);
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (fromUser) {
if (currentState == CURRENT_STATE_NORMAL) {
Toast.makeText(getContext(), "Play video first", Toast.LENGTH_SHORT).show();
return;
}
}
super.onProgressChanged(seekBar, progress, fromUser);
}
public void setUp(String url) {
super.setUp(url, JVCideoPlayerStandardSecond.SCREEN_LAYOUT_NORMAL, "");
}
}
package fm.jiecao.jcvideoplayer_lib;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Timer;
import java.util.TimerTask;
/**
* Created by Nathen
* On 2016/04/18 16:15
*/
public class JCVideoPlayerStandard extends JCVideoPlayer {
protected static Timer DISMISS_CONTROL_VIEW_TIMER;
public ImageView backButton;
public ProgressBar bottomProgressBar, loadingProgressBar;
public TextView titleTextView;
public ImageView thumbImageView;
public ImageView tinyBackImageView;
public boolean goToanother = false;
protected DismissControlViewTimerTask mDismissControlViewTimerTask;
protected Dialog mProgressDialog;
protected ProgressBar mDialogProgressBar;
protected TextView mDialogSeekTime;
protected TextView mDialogTotalTime;
protected ImageView mDialogIcon;
protected Dialog mVolumeDialog;
protected ProgressBar mDialogVolumeProgressBar;
protected TextView mDialogVolumeTextView;
protected ImageView mDialogVolumeImageView;
protected Dialog mBrightnessDialog;
protected ProgressBar mDialogBrightnessProgressBar;
protected TextView mDialogBrightnessTextView;
listener listener;
public JCVideoPlayerStandard(Context context) {
super(context);
}
public JCVideoPlayerStandard(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public void init(Context context) {
super.init(context);
bottomProgressBar = (ProgressBar) findViewById(R.id.bottom_progress);
titleTextView = (TextView) findViewById(R.id.title);
backButton = (ImageView) findViewById(R.id.back);
thumbImageView = (ImageView) findViewById(R.id.thumb);
loadingProgressBar = (ProgressBar) findViewById(R.id.loading);
tinyBackImageView = (ImageView) findViewById(R.id.back_tiny);
thumbImageView.setOnClickListener(this);
backButton.setOnClickListener(this);
tinyBackImageView.setOnClickListener(this);
}
@Override
public void setUp(String url, int screen, Object... objects) {
super.setUp(url, screen, objects);
if (objects.length == 0)
return;
titleTextView.setText(objects[0].toString());
if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
fullscreenButton.setImageResource(R.drawable.jc_shrink);
backButton.setVisibility(View.VISIBLE);
tinyBackImageView.setVisibility(View.INVISIBLE);
changeStartButtonSize((int) getResources().getDimension(R.dimen.jc_start_button_w_h_fullscreen));
} else if (currentScreen == SCREEN_LAYOUT_NORMAL
|| currentScreen == SCREEN_LAYOUT_LIST) {
fullscreenButton.setImageResource(R.drawable.jc_enlarge);
backButton.setVisibility(View.GONE);
tinyBackImageView.setVisibility(View.INVISIBLE);
changeStartButtonSize((int) getResources().getDimension(R.dimen.jc_start_button_w_h_normal));
} else if (currentScreen == SCREEN_WINDOW_TINY) {
tinyBackImageView.setVisibility(View.VISIBLE);
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.INVISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
}
}
public void changeStartButtonSize(int size) {
ViewGroup.LayoutParams lp = startButton.getLayoutParams();
lp.height = size;
lp.width = size;
lp = loadingProgressBar.getLayoutParams();
lp.height = size;
lp.width = size;
}
@Override
public int getLayoutId() {
return R.layout.jc_layout_standard;
}
@Override
public void setUiWitStateAndScreen(int state) {
super.setUiWitStateAndScreen(state);
switch (currentState) {
case CURRENT_STATE_NORMAL:
changeUiToNormal();
break;
case CURRENT_STATE_PREPARING:
changeUiToPreparingShow();
startDismissControlViewTimer();
break;
case CURRENT_STATE_PLAYING:
changeUiToPlayingShow();
startDismissControlViewTimer();
break;
case CURRENT_STATE_PAUSE:
changeUiToPauseShow();
cancelDismissControlViewTimer();
break;
case CURRENT_STATE_ERROR:
changeUiToError();
break;
case CURRENT_STATE_AUTO_COMPLETE:
changeUiToCompleteShow();
cancelDismissControlViewTimer();
bottomProgressBar.setProgress(100);
break;
case CURRENT_STATE_PLAYING_BUFFERING_START:
changeUiToPlayingBufferingShow();
break;
}
}
@Override
public boolean onTouch(View v, MotionEvent event) {
int id = v.getId();
if (id == R.id.surface_container) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// 跳到全屏
if (currentState == CURRENT_STATE_PLAYING) {
if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
backPress();
goToanother = false;
} else {
goToanother = false;
startWindowFullscreen();
}
}
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
startDismissControlViewTimer();
if (mChangePosition) {
int duration = getDuration();
int progress = mSeekTimePosition * 100 / (duration == 0 ? 1 : duration);
bottomProgressBar.setProgress(progress);
}
if (!mChangePosition && !mChangeVolume) {
onEvent(JCUserActionStandard.ON_CLICK_BLANK);
onClickUiToggle();
}
break;
}
} else if (id == R.id.bottom_seek_progress) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
cancelDismissControlViewTimer();
break;
case MotionEvent.ACTION_UP:
startDismissControlViewTimer();
break;
}
} else if (id == R.id.gotoanother) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// 跳到全屏
if (currentState != 5 && currentState != 0) {
if (currentState == CURRENT_STATE_PLAYING) {
if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
backPress();
goToanother = false;
} else {
goToanother = false;
startWindowFullscreen();
}
}
}
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
if (currentState != 5 && currentState != 0) {
startDismissControlViewTimer();
if (mChangePosition) {
int duration = getDuration();
int progress = mSeekTimePosition * 100 / (duration == 0 ? 1 : duration);
bottomProgressBar.setProgress(progress);
}
if (!mChangePosition && !mChangeVolume) {
onEvent(JCUserActionStandard.ON_CLICK_BLANK);
onClickUiToggle();
}
}
break;
}
}
return super.onTouch(v, event);
}
@Override
public void onClick(View v) {
super.onClick(v);
int i = v.getId();
if (i == R.id.thumb) {
if (TextUtils.isEmpty(url)) {
Toast.makeText(getContext(), getResources().getString(R.string.no_url), Toast.LENGTH_SHORT).show();
return;
}
if (currentState == CURRENT_STATE_NORMAL) {
if (!url.startsWith("file") && !url.startsWith("/") &&
!JCUtils.isWifiConnected(getContext()) && !WIFI_TIP_DIALOG_SHOWED) {
showWifiDialog();
return;
}
} else if (currentState == CURRENT_STATE_AUTO_COMPLETE) {
onClickUiToggle();
}
} else if (i == R.id.surface_container) {
startDismissControlViewTimer();
} else if (i == R.id.back) {
backPress();
} else if (i == R.id.back_tiny) {
backPress();
} else if (i == R.id.gotoanother) {
if (currentState == 5 || currentState == 0) {
if (currentScreen != SCREEN_WINDOW_FULLSCREEN) {
if (listener != null) {
if (listener != null) {
listener.click();
}
}
} else if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
backPress();
}
}
if (currentState != 5 && currentState != 0) {
if (currentState == CURRENT_STATE_PLAYING) {
if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
backPress();
goToanother = false;
} else {
goToanother = false;
startWindowFullscreen();
}
} else {
if (listener != null) {
if (listener != null) {
listener.click();
}
}
}
}
}
}
@Override
public void showWifiDialog() {
super.showWifiDialog();
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setMessage(getResources().getString(R.string.tips_not_wifi));
builder.setPositiveButton(getResources().getString(R.string.tips_not_wifi_confirm), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
startVideo();
WIFI_TIP_DIALOG_SHOWED = true;
}
});
builder.setNegativeButton(getResources().getString(R.string.tips_not_wifi_cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
super.onStartTrackingTouch(seekBar);
cancelDismissControlViewTimer();
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
super.onStopTrackingTouch(seekBar);
startDismissControlViewTimer();
}
public void startVideo() {
prepareMediaPlayer();
onEvent(JCUserActionStandard.ON_CLICK_START_THUMB);
}
public void onClickUiToggle() {
if (currentState == CURRENT_STATE_PREPARING) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToPreparingClear();
} else {
changeUiToPreparingShow();
}
} else if (currentState == CURRENT_STATE_PLAYING) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToPlayingClear();
} else {
changeUiToPlayingShow();
}
} else if (currentState == CURRENT_STATE_PAUSE) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToPauseClear();
} else {
changeUiToPauseShow();
}
} else if (currentState == CURRENT_STATE_AUTO_COMPLETE) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToCompleteClear();
} else {
changeUiToCompleteShow();
}
} else if (currentState == CURRENT_STATE_PLAYING_BUFFERING_START) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToPlayingBufferingClear();
} else {
changeUiToPlayingBufferingShow();
}
}
}
public void onCLickUiToggleToClear() {
if (currentState == CURRENT_STATE_PREPARING) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToPreparingClear();
} else {
}
} else if (currentState == CURRENT_STATE_PLAYING) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToPlayingClear();
} else {
}
} else if (currentState == CURRENT_STATE_PAUSE) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToPauseClear();
} else {
}
} else if (currentState == CURRENT_STATE_AUTO_COMPLETE) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToCompleteClear();
} else {
}
} else if (currentState == CURRENT_STATE_PLAYING_BUFFERING_START) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToPlayingBufferingClear();
} else {
}
}
}
@Override
public void setProgressAndText() {
super.setProgressAndText();
int position = getCurrentPositionWhenPlaying();
int duration = getDuration();
int progress = position * 100 / (duration == 0 ? 1 : duration);
if (progress != 0)
bottomProgressBar.setProgress(progress);
}
@Override
public void setBufferProgress(int bufferProgress) {
super.setBufferProgress(bufferProgress);
if (bufferProgress != 0)
bottomProgressBar.setSecondaryProgress(bufferProgress);
}
@Override
public void resetProgressAndTime() {
super.resetProgressAndTime();
bottomProgressBar.setProgress(0);
bottomProgressBar.setSecondaryProgress(0);
}
//Unified management Ui
public void changeUiToNormal() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.VISIBLE, View.INVISIBLE, View.VISIBLE,
View.INVISIBLE, View.VISIBLE, View.VISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.VISIBLE, View.INVISIBLE, View.VISIBLE,
View.INVISIBLE, View.VISIBLE, View.VISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToPreparingShow() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.VISIBLE, View.INVISIBLE, View.INVISIBLE,
View.VISIBLE, View.VISIBLE, View.VISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.VISIBLE, View.INVISIBLE, View.INVISIBLE,
View.VISIBLE, View.VISIBLE, View.VISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToPreparingClear() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.VISIBLE, View.INVISIBLE, View.INVISIBLE,
View.VISIBLE, View.VISIBLE, View.VISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.VISIBLE, View.INVISIBLE, View.INVISIBLE,
View.VISIBLE, View.VISIBLE, View.VISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_TINY:
break;
}
}
//JustPreparedUi
@Override
public void onPrepared() {
super.onPrepared();
setAllControlsVisible(View.VISIBLE, View.INVISIBLE, View.INVISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.VISIBLE);
startDismissControlViewTimer();
}
public void changeUiToPlayingShow() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.VISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.VISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToPlayingClear() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.INVISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.VISIBLE);
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.INVISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.VISIBLE);
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToPauseShow() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.VISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.VISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToPauseClear() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.INVISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.INVISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToPlayingBufferingShow() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.INVISIBLE,
View.VISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.INVISIBLE,
View.VISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToPlayingBufferingClear() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.INVISIBLE,
View.VISIBLE, View.INVISIBLE, View.INVISIBLE, View.VISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.INVISIBLE,
View.VISIBLE, View.INVISIBLE, View.INVISIBLE, View.VISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToCompleteShow() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.VISIBLE,
View.INVISIBLE, View.VISIBLE, View.INVISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.VISIBLE,
View.INVISIBLE, View.VISIBLE, View.INVISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToCompleteClear() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.VISIBLE,
View.INVISIBLE, View.VISIBLE, View.INVISIBLE, View.VISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.VISIBLE,
View.INVISIBLE, View.VISIBLE, View.INVISIBLE, View.VISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToError() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.VISIBLE,
View.INVISIBLE, View.INVISIBLE, View.VISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.VISIBLE,
View.INVISIBLE, View.INVISIBLE, View.VISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void setAllControlsVisible(int topCon, int bottomCon, int startBtn, int loadingPro,
int thumbImg, int coverImg, int bottomPro) {
topContainer.setVisibility(topCon);
//bottomContainer.setVisibility(bottomCon);
startButton.setVisibility(startBtn);
loadingProgressBar.setVisibility(loadingPro);
thumbImageView.setVisibility(thumbImg);
bottomProgressBar.setVisibility(bottomPro);
}
public void updateStartImage() {
if (currentState == CURRENT_STATE_PLAYING) {
startButton.setImageResource(R.drawable.jc_click_pause_selector);
} else if (currentState == CURRENT_STATE_ERROR) {
startButton.setImageResource(R.drawable.jc_click_error_selector);
} else {
startButton.setImageResource(R.drawable.jc_click_play_selector);
}
}
@Override
public 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.jc_dialog_progress, null);
mDialogProgressBar = ((ProgressBar) localView.findViewById(R.id.duration_progressbar));
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.jc_style_dialog_progress);
mProgressDialog.setContentView(localView);
mProgressDialog.getWindow().addFlags(Window.FEATURE_ACTION_BAR);
mProgressDialog.getWindow().addFlags(32);
mProgressDialog.getWindow().addFlags(16);
mProgressDialog.getWindow().setLayout(-2, -2);
WindowManager.LayoutParams localLayoutParams = mProgressDialog.getWindow().getAttributes();
localLayoutParams.gravity = Gravity.CENTER;
mProgressDialog.getWindow().setAttributes(localLayoutParams);
}
if (!mProgressDialog.isShowing()) {
mProgressDialog.show();
}
mDialogSeekTime.setText(seekTime);
mDialogTotalTime.setText(" / " + totalTime);
mDialogProgressBar.setProgress(totalTimeDuration <= 0 ? 0 : (seekTimePosition * 100 / totalTimeDuration));
if (deltaX > 0) {
mDialogIcon.setBackgroundResource(R.drawable.jc_forward_icon);
} else {
mDialogIcon.setBackgroundResource(R.drawable.jc_backward_icon);
}
onCLickUiToggleToClear();
}
@Override
public void dismissProgressDialog() {
super.dismissProgressDialog();
if (mProgressDialog != null) {
mProgressDialog.dismiss();
}
}
@Override
public void showVolumeDialog(float deltaY, int volumePercent) {
super.showVolumeDialog(deltaY, volumePercent);
if (mVolumeDialog == null) {
View localView = LayoutInflater.from(getContext()).inflate(R.layout.jc_dialog_volume, null);
mDialogVolumeImageView = ((ImageView) localView.findViewById(R.id.volume_image_tip));
mDialogVolumeTextView = ((TextView) localView.findViewById(R.id.tv_volume));
mDialogVolumeProgressBar = ((ProgressBar) localView.findViewById(R.id.volume_progressbar));
mVolumeDialog = new Dialog(getContext(), R.style.jc_style_dialog_progress);
mVolumeDialog.setContentView(localView);
mVolumeDialog.getWindow().addFlags(8);
mVolumeDialog.getWindow().addFlags(32);
mVolumeDialog.getWindow().addFlags(16);
mVolumeDialog.getWindow().setLayout(-2, -2);
WindowManager.LayoutParams localLayoutParams = mVolumeDialog.getWindow().getAttributes();
localLayoutParams.gravity = Gravity.CENTER;
mVolumeDialog.getWindow().setAttributes(localLayoutParams);
}
if (!mVolumeDialog.isShowing()) {
mVolumeDialog.show();
}
if (volumePercent <= 0) {
mDialogVolumeImageView.setBackgroundResource(R.drawable.jc_close_volume);
} else {
mDialogVolumeImageView.setBackgroundResource(R.drawable.jc_add_volume);
}
if (volumePercent > 100) {
volumePercent = 100;
} else if (volumePercent < 0) {
volumePercent = 0;
}
mDialogVolumeTextView.setText(volumePercent + "%");
mDialogVolumeProgressBar.setProgress(volumePercent);
onCLickUiToggleToClear();
}
@Override
public void dismissVolumeDialog() {
super.dismissVolumeDialog();
if (mVolumeDialog != null) {
mVolumeDialog.dismiss();
}
}
@Override
public void showBrightnessDialog(int brightnessPercent) {
super.showBrightnessDialog(brightnessPercent);
if (mBrightnessDialog == null) {
View localView = LayoutInflater.from(getContext()).inflate(R.layout.jc_dialog_brightness, null);
mDialogBrightnessTextView = ((TextView) localView.findViewById(R.id.tv_brightness));
mDialogBrightnessProgressBar = ((ProgressBar) localView.findViewById(R.id.brightness_progressbar));
mBrightnessDialog = new Dialog(getContext(), R.style.jc_style_dialog_progress);
mBrightnessDialog.setContentView(localView);
mBrightnessDialog.getWindow().addFlags(Window.FEATURE_ACTION_BAR);
mBrightnessDialog.getWindow().addFlags(32);
mBrightnessDialog.getWindow().addFlags(16);
mBrightnessDialog.getWindow().setLayout(-2, -2);
WindowManager.LayoutParams localLayoutParams = mBrightnessDialog.getWindow().getAttributes();
localLayoutParams.gravity = Gravity.CENTER;
mBrightnessDialog.getWindow().setAttributes(localLayoutParams);
}
if (!mBrightnessDialog.isShowing()) {
mBrightnessDialog.show();
}
if (brightnessPercent > 100) {
brightnessPercent = 100;
} else if (brightnessPercent < 0) {
brightnessPercent = 0;
}
mDialogBrightnessTextView.setText(brightnessPercent + "%");
mDialogBrightnessProgressBar.setProgress(brightnessPercent);
onCLickUiToggleToClear();
}
@Override
public void dismissBrightnessDialog() {
super.dismissBrightnessDialog();
if (mBrightnessDialog != null) {
mBrightnessDialog.dismiss();
}
}
public void startDismissControlViewTimer() {
cancelDismissControlViewTimer();
DISMISS_CONTROL_VIEW_TIMER = new Timer();
mDismissControlViewTimerTask = new DismissControlViewTimerTask();
DISMISS_CONTROL_VIEW_TIMER.schedule(mDismissControlViewTimerTask, 2500);
}
public void cancelDismissControlViewTimer() {
if (DISMISS_CONTROL_VIEW_TIMER != null) {
DISMISS_CONTROL_VIEW_TIMER.cancel();
}
if (mDismissControlViewTimerTask != null) {
mDismissControlViewTimerTask.cancel();
}
}
@Override
public void onAutoCompletion() {
super.onAutoCompletion();
cancelDismissControlViewTimer();
}
@Override
public void onCompletion() {
super.onCompletion();
cancelDismissControlViewTimer();
}
public JCVideoPlayerStandard.listener getListener() {
return listener;
}
public void setListener(JCVideoPlayerStandard.listener listener) {
this.listener = listener;
}
public interface listener {
void click();
}
public class DismissControlViewTimerTask extends TimerTask {
@Override
public void run() {
if (currentState != CURRENT_STATE_NORMAL
&& currentState != CURRENT_STATE_ERROR
&& currentState != CURRENT_STATE_AUTO_COMPLETE) {
if (getContext() != null && getContext() instanceof Activity) {
((Activity) getContext()).runOnUiThread(new Runnable() {
@Override
public void run() {
bottomContainer.setVisibility(View.INVISIBLE);
topContainer.setVisibility(View.INVISIBLE);
startButton.setVisibility(View.INVISIBLE);
if (currentScreen != SCREEN_WINDOW_TINY) {
bottomProgressBar.setVisibility(View.VISIBLE);
}
}
});
}
}
}
}
}
package fm.jiecao.jcvideoplayer_lib;
import android.content.Context;
import android.media.AudioManager;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.FrameLayout;
/**
* Created by xuan on 2018-11-26 12:08:11.
* <p>
* 使用基于jcv视频播放器改造而成,用于短视频模块视频播放预览
*/
public class JCVideoViewbyXuan extends FrameLayout implements OnJcvdListener {
public int mCurrState;
public boolean loop = true;
public String mCurrUrl = "";
public boolean isForceFullScreenPlay;
protected AudioManager mAudioManager;
private OnJcvdListener mListener;
private AudioManager.OnAudioFocusChangeListener onAudioFocusChangeListener = new AudioManager.OnAudioFocusChangeListener() {
@Override
public void onAudioFocusChange(int focusChange) {
if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
VideotillManager.instance().releaseVideo();
JCMediaManager.instance().releaseMediaPlayer();
} else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
try {
if (JCMediaManager.instance().mediaPlayer != null && JCMediaManager.instance().mediaPlayer.isPlaying()) {
JCMediaManager.instance().mediaPlayer.pause();
}
} catch (Exception e) {
}
}
}
};
public JCVideoViewbyXuan(Context context) {
super(context);
init(context);
}
public JCVideoViewbyXuan(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
private void init(Context context) {
mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
mAudioManager.requestAudioFocus(onAudioFocusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
}
public void setForceFullScreenPlay(boolean forceFullScreenPlay) {
isForceFullScreenPlay = forceFullScreenPlay;
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
if (isForceFullScreenPlay) {
int width = getDefaultSize(0, widthMeasureSpec);
int height = getDefaultSize(0, heightMeasureSpec);
setMeasuredDimension(width, height);
} else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
// setMeasuredDimension();
}
private void prepare() {
VideotillManager.instance().releaseVideo();
// 移除 管理器中的 textureView
JCMediaManager.savedSurfaceTexture = null;
if (JCMediaManager.textureView != null && JCMediaManager.textureView.getParent() != null) {
((ViewGroup) JCMediaManager.textureView.getParent()).removeView(JCMediaManager.textureView);
}
// 创建一个新的 textureView
JCMediaManager.textureView = new JCResizeTextureView(getContext());
JCMediaManager.textureView.setSurfaceTextureListener(JCMediaManager.instance());
// 放到容器中
LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, Gravity.CENTER);
this.addView(JCMediaManager.textureView, layoutParams);
// 当播放时才有焦点
JCUtils.scanForActivity(getContext()).getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
JCMediaManager.CURRENT_PLAYING_URL = this.mCurrUrl;
JCMediaManager.CURRENT_PLING_LOOP = loop;
JCMediaManager.MAP_HEADER_DATA = null;
JCMediaManager.addOnJcvdListener(this);
VideotillManager.instance().addVideoPlay(this);
mCurrState = JCVideoPlayer.CURRENT_STATE_PREPARING;
}
/**
* 播放 或 继续播放
*
* @param url
*/
public void play(String url) {
Log.e("xuan", "play: " + url + " state :" + mCurrState);
if (mCurrState == JCVideoPlayer.CURRENT_STATE_NORMAL) {
if (TextUtils.isEmpty(url)) {
return;
}
this.mCurrUrl = url;
prepare(); // !JCUtils.isWifiConnected(getContext()) 判断网络
} else if (mCurrState == JCVideoPlayer.CURRENT_STATE_PAUSE) {
JCMediaManager.instance().mediaPlayer.start(); // 开始
if (mListener != null) {
mListener.onPrepared();
}
mCurrState = JCVideoPlayer.CURRENT_STATE_PLAYING;
}
}
/**
* 暂停播放
*/
public void pause() {
Log.e("xuan", "pause: " + mCurrState);
if (mCurrState == JCVideoPlayer.CURRENT_STATE_PLAYING) {
if (JCMediaManager.instance().mediaPlayer.isPlaying()) {
JCMediaManager.instance().mediaPlayer.pause(); // 暂停
}
mCurrState = JCVideoPlayer.CURRENT_STATE_PAUSE;
if (mListener != null) {
mListener.onPause();
}
}
}
/**
* 停止播放
*/
public void stop() {
Log.e("xuan", "stop: " + mCurrState);
mCurrState = JCVideoPlayer.CURRENT_STATE_NORMAL;
JCMediaManager.instance().releaseMediaPlayer();
// 加上这句,避免循环播放video的时候,内存不断飙升。
Runtime.getRuntime().gc();
}
public void reset() {
Log.e("xuan", "reset: ");
JCMediaManager.instance().releaseMediaPlayer();
mCurrState = JCVideoPlayer.CURRENT_STATE_NORMAL;
// 清理缓存变量
this.removeView(JCMediaManager.textureView);
mAudioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
mAudioManager.abandonAudioFocus(onAudioFocusChangeListener);
JCMediaManager.textureView = null;
JCMediaManager.savedSurfaceTexture = null;
// 加上这句,避免循环播放video的时候,内存不断飙升。
Runtime.getRuntime().gc();
if (mListener != null) {
mListener.onReset();
}
}
/**
* 修改系统音乐音量
*
* @param volume +10 or -10
*/
public void changeVolume(int volume) {
if (mCurrState == JCVideoPlayer.CURRENT_STATE_PLAYING && mAudioManager != null) {
// int max = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int curr = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, curr + volume, 0);
}
}
/**
* 修改当前播放进度
*/
public void changeProgress(int pro) {
// 得到视频长度
int duration = getDuration();
// 将长度转换成时间
String totalTime = JCUtils.stringForTime(duration);
// 跳转到一个位置 毫秒
JCMediaManager.instance().mediaPlayer.seekTo(1000);
// 保存一个url的进度 or 清除进度
JCUtils.saveProgress(getContext(), mCurrUrl, 0);
JCUtils.clearSavedProgress(getContext(), mCurrUrl);
}
public void seekTo(int msec) {
// 跳转到一个位置 毫秒
JCMediaManager.instance().mediaPlayer.seekTo(msec);
}
/**
* 加载完成开始播放的回掉
*/
@Override
public void onPrepared() {
Log.e("xuan", "开始播放: " + mCurrUrl);
mCurrState = JCVideoPlayer.CURRENT_STATE_PLAYING;
if (mListener != null) {
mListener.onPrepared();
}
}
// 播放完成的回调
@Override
public void onCompletion() {
Log.e("xuan", "播放完成: ");
mCurrState = JCVideoPlayer.CURRENT_STATE_NORMAL;
if (mListener != null) {
mListener.onCompletion();
}
if (loop) {
mCurrState = JCVideoPlayer.CURRENT_STATE_PAUSE;
play(this.mCurrUrl);
}
}
@Override
public void onError() {
Log.e("xuan", "播放出错: " + mCurrUrl);
JCMediaManager.instance().releaseMediaPlayer();
mCurrState = JCVideoPlayer.CURRENT_STATE_NORMAL;
if (mListener != null) {
mListener.onError();
}
}
@Override
public void onPause() {
}
@Override
public void onReset() {
}
public int getCurrentProgress() {
int position = 0;
if (mCurrState == JCVideoPlayer.CURRENT_STATE_PLAYING || mCurrState == JCVideoPlayer.CURRENT_STATE_PAUSE) {
try {
position = JCMediaManager.instance().mediaPlayer.getCurrentPosition();
} catch (IllegalStateException e) {
e.printStackTrace();
return position;
}
}
return position;
}
public int getDuration() {
int duration = 0;
try {
duration = JCMediaManager.instance().mediaPlayer.getDuration();
} catch (IllegalStateException e) {
e.printStackTrace();
return duration;
}
return duration;
}
public void addOnJcvdListener(OnJcvdListener listener) {
this.mListener = listener;
}
public boolean isPlaying() {
return mCurrState == JCVideoPlayer.CURRENT_STATE_PLAYING;
}
}
package fm.jiecao.jcvideoplayer_lib;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.net.Uri;
import android.provider.MediaStore;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
import java.util.Timer;
import java.util.TimerTask;
/**
* 生活圈播放器
* Todo Modify by zq in 2018.12.3 reference by JVCideoPlayerStandardforchat
*/
public class JVCideoPlayerStandardSecond extends JCVideoPlayer {
protected static Timer DISMISS_CONTROL_VIEW_TIMER;
public ImageView thumbImageView;
public ImageView tinyBackImageView;
public ImageView backButton;
public TextView titleTextView;
public ProgressBar bottomProgressBar, loadingProgressBar;
protected DismissControlViewTimerTask mDismissControlViewTimerTask;
protected Dialog mProgressDialog;
protected ProgressBar mDialogProgressBar;
protected TextView mDialogSeekTime;
protected TextView mDialogTotalTime;
protected ImageView mDialogIcon;
protected Dialog mVolumeDialog;
protected ProgressBar mDialogVolumeProgressBar;
protected TextView mDialogVolumeTextView;
protected ImageView mDialogVolumeImageView;
protected Dialog mBrightnessDialog;
protected ProgressBar mDialogBrightnessProgressBar;
protected TextView mDialogBrightnessTextView;
private Context mContext;
private SavaVideoDialog savaVideoDialog;
SavaVideoDialog.OnSavaVideoDialogClickListener onSavaVideoDialogClickListener = new SavaVideoDialog.OnSavaVideoDialogClickListener() {
@Override
public void tv1Click() {
downloadUrl(url);
Log.e("zx", "tv1Click: " + url);
}
};
public JVCideoPlayerStandardSecond(Context context) {
super(context);
this.mContext = context;
}
public JVCideoPlayerStandardSecond(Context context, AttributeSet attrs) {
super(context, attrs);
this.mContext = context;
}
@Override
public int getLayoutId() {
return R.layout.jc_layout_standard;
}
@Override
public void init(final Context context) {
super.init(context);
thumbImageView = (ImageView) findViewById(R.id.thumb);
tinyBackImageView = (ImageView) findViewById(R.id.back_tiny);
backButton = (ImageView) findViewById(R.id.back);
titleTextView = (TextView) findViewById(R.id.title);
loadingProgressBar = (ProgressBar) findViewById(R.id.loading);
bottomProgressBar = (ProgressBar) findViewById(R.id.bottom_progress);
findViewById(R.id.gotoanother).setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Log.e("zx", "onLongClick: ");
savaVideoDialog = new SavaVideoDialog(context, onSavaVideoDialogClickListener);
savaVideoDialog.show();
return false;
}
});
thumbImageView.setOnClickListener(this);
tinyBackImageView.setOnClickListener(this);
backButton.setOnClickListener(this);
}
private void downloadUrl(String mVideoPath) {
// /storage/emulated/0/Android/data/com.sk.weichat/files/10009550/Music/f2e825871bd648e4ad85c4f09eab5890.mp4
// file:///storage/emulated/0/Android/data/com.sk.weichat/cache/video-cache/88b2aaa62a7192a612.mp4
// /storage/emulated/0/Android/data/com.sk.weichat/cache/video-cache/88b2aaa62a7192a612.mp4
File file = new File(mVideoPath.substring(7, mVideoPath.length()));
ContentResolver localResolver = mContext.getContentResolver();
ContentValues localContentValue = getVideoContentValues(file, System.currentTimeMillis());
Uri uri = localResolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, localContentValue);
Log.e("zx", "downloadUrl: " + uri);
Toast.makeText(mContext, "视频已保存", Toast.LENGTH_SHORT).show();
if (mVideoPath.startsWith("http")) {
String path = "/storage/emulated/0/Android/data/com.sk.weichat/files/Movies" +
mVideoPath.substring(mVideoPath.length() - 6, mVideoPath.length() - 4) + ".mp4";
File f = new File(path);
if (!f.exists()) {
new downloadTask(mVideoPath, 2, path).start();
ContentResolver localContentResolver = mContext.getContentResolver();
ContentValues localContentValues = getVideoContentValues(f, System.currentTimeMillis());
localContentResolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, localContentValues);
Toast.makeText(mContext, "视频已保存", Toast.LENGTH_SHORT).show();
} else
Toast.makeText(mContext, "视频已存在", Toast.LENGTH_SHORT).show();
}
savaVideoDialog.dismiss();
}
public ContentValues getVideoContentValues(File paramFile, long paramLong) {
ContentValues localContentValues = new ContentValues();
localContentValues.put("title", paramFile.getName());
localContentValues.put("_display_name", paramFile.getName());
localContentValues.put("mime_type", "video/3gp");
localContentValues.put("datetaken", Long.valueOf(paramLong));
localContentValues.put("date_modified", Long.valueOf(paramLong));
localContentValues.put("date_added", Long.valueOf(paramLong));
localContentValues.put("_data", paramFile.getAbsolutePath());
localContentValues.put("_size", Long.valueOf(paramFile.length()));
return localContentValues;
}
@Override
public void setUp(String url, int screen, Object... objects) {
super.setUp(url, screen, objects);
if (objects.length == 0)
return;
titleTextView.setText(objects[0].toString());
if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
fullscreenButton.setImageResource(R.drawable.jc_shrink);
backButton.setVisibility(View.VISIBLE);
tinyBackImageView.setVisibility(View.INVISIBLE);
changeStartButtonSize((int) getResources().getDimension(R.dimen.jc_start_button_w_h_fullscreen));
} else if (currentScreen == SCREEN_LAYOUT_NORMAL
|| currentScreen == SCREEN_LAYOUT_LIST) {
fullscreenButton.setImageResource(R.drawable.jc_enlarge);
backButton.setVisibility(View.GONE);
tinyBackImageView.setVisibility(View.INVISIBLE);
changeStartButtonSize((int) getResources().getDimension(R.dimen.jc_start_button_w_h_normal));
} else if (currentScreen == SCREEN_WINDOW_TINY) {
tinyBackImageView.setVisibility(View.VISIBLE);
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.INVISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
}
}
public void changeStartButtonSize(int size) {
ViewGroup.LayoutParams lp = startButton.getLayoutParams();
lp.height = size;
lp.width = size;
lp = loadingProgressBar.getLayoutParams();
lp.height = size;
lp.width = size;
}
@Override
public void onClick(View v) {
super.onClick(v);
int i = v.getId();
if (i == R.id.gotoanother) {
if (currentState != CURRENT_STATE_NORMAL
&& currentState != CURRENT_STATE_PREPARING
&& currentState != CURRENT_STATE_AUTO_COMPLETE) {
if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
if (!backPress()) {
startWindowFullscreen();
} else {
JCMediaManager.instance().recoverMediaPlayer();
}
} else {
if (!startWindowFullscreen()) {
backPress();
}
}
}
}
}
@Override
public void showWifiDialog() {
super.showWifiDialog();
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setMessage(getResources().getString(R.string.tips_not_wifi));
builder.setPositiveButton(getResources().getString(R.string.tips_not_wifi_confirm), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
startVideo();
WIFI_TIP_DIALOG_SHOWED = true;
}
});
builder.setNegativeButton(getResources().getString(R.string.tips_not_wifi_cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}
@Override
public void onAutoCompletion() {
if (JCVideoPlayerManager.getSecondFloor() != null) {// 全屏模式,循环播放
JCMediaManager.instance().mediaPlayer.start();
} else {// 调用父类onAutoCompletion方法
super.onAutoCompletion();
cancelDismissControlViewTimer();
}
}
@Override
public void onCompletion() {
super.onCompletion();
cancelDismissControlViewTimer();
}
@Override
public void setUiWitStateAndScreen(int state) {
super.setUiWitStateAndScreen(state);
switch (currentState) {
case CURRENT_STATE_NORMAL:
changeUiToNormal();
break;
case CURRENT_STATE_PREPARING:
changeUiToPreparingShow();
startDismissControlViewTimer();
break;
case CURRENT_STATE_PLAYING:
changeUiToPlayingShow();
startDismissControlViewTimer();
break;
case CURRENT_STATE_PAUSE:
changeUiToPauseShow();
cancelDismissControlViewTimer();
break;
case CURRENT_STATE_ERROR:
changeUiToError();
break;
case CURRENT_STATE_AUTO_COMPLETE:
changeUiToCompleteShow();
cancelDismissControlViewTimer();
bottomProgressBar.setProgress(100);
break;
case CURRENT_STATE_PLAYING_BUFFERING_START:
changeUiToPlayingBufferingShow();
break;
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
super.onStartTrackingTouch(seekBar);
cancelDismissControlViewTimer();
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
super.onStopTrackingTouch(seekBar);
startDismissControlViewTimer();
}
public void startVideo() {
prepareMediaPlayer();
onEvent(JCUserActionStandard.ON_CLICK_START_THUMB);
}
public void onClickUiToggle() {
if (currentState == CURRENT_STATE_PREPARING) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToPreparingClear();
} else {
changeUiToPreparingShow();
}
} else if (currentState == CURRENT_STATE_PLAYING) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToPlayingClear();
} else {
changeUiToPlayingShow();
}
} else if (currentState == CURRENT_STATE_PAUSE) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToPauseClear();
} else {
changeUiToPauseShow();
}
} else if (currentState == CURRENT_STATE_AUTO_COMPLETE) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToCompleteClear();
} else {
changeUiToCompleteShow();
}
} else if (currentState == CURRENT_STATE_PLAYING_BUFFERING_START) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToPlayingBufferingClear();
} else {
changeUiToPlayingBufferingShow();
}
}
}
public void onCLickUiToggleToClear() {
if (currentState == CURRENT_STATE_PREPARING) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToPreparingClear();
} else {
}
} else if (currentState == CURRENT_STATE_PLAYING) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToPlayingClear();
} else {
}
} else if (currentState == CURRENT_STATE_PAUSE) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToPauseClear();
} else {
}
} else if (currentState == CURRENT_STATE_AUTO_COMPLETE) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToCompleteClear();
} else {
}
} else if (currentState == CURRENT_STATE_PLAYING_BUFFERING_START) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToPlayingBufferingClear();
} else {
}
}
}
@Override
public void setProgressAndText() {
super.setProgressAndText();
int position = getCurrentPositionWhenPlaying();
int duration = getDuration();
int progress = position * 100 / (duration == 0 ? 1 : duration);
if (progress != 0)
bottomProgressBar.setProgress(progress);
}
@Override
public void setBufferProgress(int bufferProgress) {
super.setBufferProgress(bufferProgress);
if (bufferProgress != 0)
bottomProgressBar.setSecondaryProgress(bufferProgress);
}
@Override
public void resetProgressAndTime() {
super.resetProgressAndTime();
bottomProgressBar.setProgress(0);
bottomProgressBar.setSecondaryProgress(0);
}
//Unified management Ui
public void changeUiToNormal() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.VISIBLE, View.INVISIBLE, View.VISIBLE,
View.INVISIBLE, View.VISIBLE, View.VISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.VISIBLE, View.INVISIBLE, View.VISIBLE,
View.INVISIBLE, View.VISIBLE, View.VISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToPreparingShow() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.VISIBLE, View.INVISIBLE, View.INVISIBLE,
View.VISIBLE, View.VISIBLE, View.VISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.VISIBLE, View.INVISIBLE, View.INVISIBLE,
View.VISIBLE, View.VISIBLE, View.VISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToPreparingClear() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.VISIBLE, View.INVISIBLE, View.INVISIBLE,
View.VISIBLE, View.VISIBLE, View.VISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.VISIBLE, View.INVISIBLE, View.INVISIBLE,
View.VISIBLE, View.VISIBLE, View.VISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_TINY:
break;
}
}
//JustPreparedUi
@Override
public void onPrepared() {
super.onPrepared();
setAllControlsVisible(View.VISIBLE, View.INVISIBLE, View.INVISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.VISIBLE);
startDismissControlViewTimer();
}
public void changeUiToPlayingShow() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.VISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.VISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToPlayingClear() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.INVISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.VISIBLE);
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.INVISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.VISIBLE);
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToPauseShow() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.VISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.VISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToPauseClear() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.INVISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.INVISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToPlayingBufferingShow() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.INVISIBLE,
View.VISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.INVISIBLE,
View.VISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToPlayingBufferingClear() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.INVISIBLE,
View.VISIBLE, View.INVISIBLE, View.INVISIBLE, View.VISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.INVISIBLE,
View.VISIBLE, View.INVISIBLE, View.INVISIBLE, View.VISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToCompleteShow() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.VISIBLE,
View.INVISIBLE, View.VISIBLE, View.INVISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.VISIBLE,
View.INVISIBLE, View.VISIBLE, View.INVISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToCompleteClear() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.VISIBLE,
View.INVISIBLE, View.VISIBLE, View.INVISIBLE, View.VISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.VISIBLE,
View.INVISIBLE, View.VISIBLE, View.INVISIBLE, View.VISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToError() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.VISIBLE,
View.INVISIBLE, View.INVISIBLE, View.VISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.VISIBLE,
View.INVISIBLE, View.INVISIBLE, View.VISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void setAllControlsVisible(int topCon, int bottomCon, int startBtn, int loadingPro,
int thumbImg, int coverImg, int bottomPro) {
topContainer.setVisibility(topCon);
// bottomContainer.setVisibility(bottomCon);
startButton.setVisibility(startBtn);
loadingProgressBar.setVisibility(loadingPro);
thumbImageView.setVisibility(thumbImg);
bottomProgressBar.setVisibility(bottomPro);
}
public void updateStartImage() {
if (currentState == CURRENT_STATE_PLAYING) {
startButton.setImageResource(R.drawable.jc_click_pause_selector);
} else if (currentState == CURRENT_STATE_ERROR) {
startButton.setImageResource(R.drawable.jc_click_error_selector);
} else {
startButton.setImageResource(R.drawable.jc_click_play_selector);
}
}
@Override
public 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.jc_dialog_progress, null);
mDialogProgressBar = ((ProgressBar) localView.findViewById(R.id.duration_progressbar));
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.jc_style_dialog_progress);
mProgressDialog.setContentView(localView);
mProgressDialog.getWindow().addFlags(Window.FEATURE_ACTION_BAR);
mProgressDialog.getWindow().addFlags(32);
mProgressDialog.getWindow().addFlags(16);
mProgressDialog.getWindow().setLayout(-2, -2);
WindowManager.LayoutParams localLayoutParams = mProgressDialog.getWindow().getAttributes();
localLayoutParams.gravity = Gravity.CENTER;
mProgressDialog.getWindow().setAttributes(localLayoutParams);
}
if (!mProgressDialog.isShowing()) {
mProgressDialog.show();
}
mDialogSeekTime.setText(seekTime);
mDialogTotalTime.setText(" / " + totalTime);
mDialogProgressBar.setProgress(totalTimeDuration <= 0 ? 0 : (seekTimePosition * 100 / totalTimeDuration));
if (deltaX > 0) {
mDialogIcon.setBackgroundResource(R.drawable.jc_forward_icon);
} else {
mDialogIcon.setBackgroundResource(R.drawable.jc_backward_icon);
}
onCLickUiToggleToClear();
}
@Override
public void dismissProgressDialog() {
super.dismissProgressDialog();
if (mProgressDialog != null) {
mProgressDialog.dismiss();
}
}
@Override
public void showVolumeDialog(float deltaY, int volumePercent) {
super.showVolumeDialog(deltaY, volumePercent);
if (mVolumeDialog == null) {
View localView = LayoutInflater.from(getContext()).inflate(R.layout.jc_dialog_volume, null);
mDialogVolumeImageView = ((ImageView) localView.findViewById(R.id.volume_image_tip));
mDialogVolumeTextView = ((TextView) localView.findViewById(R.id.tv_volume));
mDialogVolumeProgressBar = ((ProgressBar) localView.findViewById(R.id.volume_progressbar));
mVolumeDialog = new Dialog(getContext(), R.style.jc_style_dialog_progress);
mVolumeDialog.setContentView(localView);
mVolumeDialog.getWindow().addFlags(8);
mVolumeDialog.getWindow().addFlags(32);
mVolumeDialog.getWindow().addFlags(16);
mVolumeDialog.getWindow().setLayout(-2, -2);
WindowManager.LayoutParams localLayoutParams = mVolumeDialog.getWindow().getAttributes();
localLayoutParams.gravity = Gravity.CENTER;
mVolumeDialog.getWindow().setAttributes(localLayoutParams);
}
if (!mVolumeDialog.isShowing()) {
mVolumeDialog.show();
}
if (volumePercent <= 0) {
mDialogVolumeImageView.setBackgroundResource(R.drawable.jc_close_volume);
} else {
mDialogVolumeImageView.setBackgroundResource(R.drawable.jc_add_volume);
}
if (volumePercent > 100) {
volumePercent = 100;
} else if (volumePercent < 0) {
volumePercent = 0;
}
mDialogVolumeTextView.setText(volumePercent + "%");
mDialogVolumeProgressBar.setProgress(volumePercent);
onCLickUiToggleToClear();
}
@Override
public void dismissVolumeDialog() {
super.dismissVolumeDialog();
if (mVolumeDialog != null) {
mVolumeDialog.dismiss();
}
}
@Override
public void showBrightnessDialog(int brightnessPercent) {
super.showBrightnessDialog(brightnessPercent);
if (mBrightnessDialog == null) {
View localView = LayoutInflater.from(getContext()).inflate(R.layout.jc_dialog_brightness, null);
mDialogBrightnessTextView = ((TextView) localView.findViewById(R.id.tv_brightness));
mDialogBrightnessProgressBar = ((ProgressBar) localView.findViewById(R.id.brightness_progressbar));
mBrightnessDialog = new Dialog(getContext(), R.style.jc_style_dialog_progress);
mBrightnessDialog.setContentView(localView);
mBrightnessDialog.getWindow().addFlags(Window.FEATURE_ACTION_BAR);
mBrightnessDialog.getWindow().addFlags(32);
mBrightnessDialog.getWindow().addFlags(16);
mBrightnessDialog.getWindow().setLayout(-2, -2);
WindowManager.LayoutParams localLayoutParams = mBrightnessDialog.getWindow().getAttributes();
localLayoutParams.gravity = Gravity.CENTER;
mBrightnessDialog.getWindow().setAttributes(localLayoutParams);
}
if (!mBrightnessDialog.isShowing()) {
mBrightnessDialog.show();
}
if (brightnessPercent > 100) {
brightnessPercent = 100;
} else if (brightnessPercent < 0) {
brightnessPercent = 0;
}
mDialogBrightnessTextView.setText(brightnessPercent + "%");
mDialogBrightnessProgressBar.setProgress(brightnessPercent);
onCLickUiToggleToClear();
}
@Override
public void dismissBrightnessDialog() {
super.dismissBrightnessDialog();
if (mBrightnessDialog != null) {
mBrightnessDialog.dismiss();
}
}
public void startDismissControlViewTimer() {
cancelDismissControlViewTimer();
DISMISS_CONTROL_VIEW_TIMER = new Timer();
mDismissControlViewTimerTask = new DismissControlViewTimerTask();
DISMISS_CONTROL_VIEW_TIMER.schedule(mDismissControlViewTimerTask, 2500);
}
public void cancelDismissControlViewTimer() {
if (DISMISS_CONTROL_VIEW_TIMER != null) {
DISMISS_CONTROL_VIEW_TIMER.cancel();
}
if (mDismissControlViewTimerTask != null) {
mDismissControlViewTimerTask.cancel();
}
}
public class DismissControlViewTimerTask extends TimerTask {
@Override
public void run() {
if (currentState != CURRENT_STATE_NORMAL
&& currentState != CURRENT_STATE_ERROR
&& currentState != CURRENT_STATE_AUTO_COMPLETE) {
if (getContext() != null && getContext() instanceof Activity) {
((Activity) getContext()).runOnUiThread(new Runnable() {
@Override
public void run() {
bottomContainer.setVisibility(View.INVISIBLE);
topContainer.setVisibility(View.INVISIBLE);
startButton.setVisibility(View.INVISIBLE);
if (currentScreen != SCREEN_WINDOW_TINY) {
bottomProgressBar.setVisibility(View.VISIBLE);
}
}
});
}
}
}
}
}
package fm.jiecao.jcvideoplayer_lib;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.TextView;
import org.greenrobot.eventbus.EventBus;
import java.util.Timer;
import java.util.TimerTask;
/**
* 聊天界面播放器
* Todo Modify by zq in 2018.12.3
* Todo 之前导入这个库的时候,没有去研究他就开始用,很多东西自己都没有搞清楚就开始改,之后自己又写的乱七八糟,复杂了很多不必要的代码 现优化下这个类
* 注:看到分割线内的代码可以忽略掉,我认为这不是很重要的代码,先保留着不删掉
*/
public class JVCideoPlayerStandardforchat extends JCVideoPlayer {
/******************************下面的不是很重要*********************************/
protected static Timer DISMISS_CONTROL_VIEW_TIMER;
public ImageView thumbImageView;
public ImageView tinyBackImageView;
public ImageView backButton;
public TextView titleTextView;
/*
bottomProgressBar可能是自己加的,现隐藏掉,还是用框架提供的SeekBar,在该类不需要监听SeekBar的拖动进行播放进度的调整
因为JCVideoPlayer已经将什么都处理好了,包括start、pause...其实我觉得该类继承JCVideoPlayerStandard会比较好点
*/
public ProgressBar bottomProgressBar, loadingProgressBar;
protected DismissControlViewTimerTask mDismissControlViewTimerTask;
protected Dialog mProgressDialog;
protected ProgressBar mDialogProgressBar;
protected TextView mDialogSeekTime;
protected TextView mDialogTotalTime;
protected ImageView mDialogIcon;
protected Dialog mVolumeDialog;
protected ProgressBar mDialogVolumeProgressBar;
protected TextView mDialogVolumeTextView;
protected ImageView mDialogVolumeImageView;
protected Dialog mBrightnessDialog;
protected ProgressBar mDialogBrightnessProgressBar;
protected TextView mDialogBrightnessTextView;
private LinearLayout mBottomLayout;
private String mUrl;
/******************************上面的不是很重要*********************************/
public JVCideoPlayerStandardforchat(Context context) {
super(context);
noAction = true;
}
public JVCideoPlayerStandardforchat(Context context, AttributeSet attrs) {
super(context, attrs);
noAction = true;
}
public static boolean handlerBack() {
if (backPress()) {
JCMediaManager.instance().recoverMediaPlayer();
return true;
}
return false;
}
@Override
public int getLayoutId() {
return R.layout.jc_layout_forchat;
}
@Override
public void init(Context context) {
super.init(context);
thumbImageView = (ImageView) findViewById(R.id.thumb);
tinyBackImageView = (ImageView) findViewById(R.id.back_tiny);
backButton = (ImageView) findViewById(R.id.back);
titleTextView = (TextView) findViewById(R.id.title);
loadingProgressBar = (ProgressBar) findViewById(R.id.loading);
bottomProgressBar = (ProgressBar) findViewById(R.id.bottom_progress);
mBottomLayout = findViewById(R.id.layout_bottom);
tinyBackImageView.setOnClickListener(this);
gotoanother.setOnLongClickListener(new OnLongClickListener() {// 将长按事件传给聊天界面
@Override
public boolean onLongClick(View v) {
if (mListener != null) {
mListener.onLongClick();
}
return false;
}
});
}
@Override
public void setUp(String url, int screen, Object... objects) {
super.setUp(url, screen, objects);
mUrl = url;
noAction = true;
if (objects.length == 0)
return;
titleTextView.setText(objects[0].toString());
if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
fullscreenButton.setImageResource(R.drawable.jc_shrink);
backButton.setVisibility(View.VISIBLE);
tinyBackImageView.setVisibility(View.INVISIBLE);
changeStartButtonSize((int) getResources().getDimension(R.dimen.jc_start_button_w_h_fullscreen));
} else if (currentScreen == SCREEN_LAYOUT_NORMAL
|| currentScreen == SCREEN_LAYOUT_LIST) {
fullscreenButton.setImageResource(R.drawable.jc_enlarge);
backButton.setVisibility(View.GONE);
tinyBackImageView.setVisibility(View.INVISIBLE);
changeStartButtonSize((int) getResources().getDimension(R.dimen.jc_start_button_w_h_normal));
} else if (currentScreen == SCREEN_WINDOW_TINY) {
tinyBackImageView.setVisibility(View.VISIBLE);
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.INVISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
}
}
public void changeStartButtonSize(int size) {
ViewGroup.LayoutParams lp = startButton.getLayoutParams();
lp.height = size;
lp.width = size;
lp = loadingProgressBar.getLayoutParams();
lp.height = size;
lp.width = size;
}
@Override
public void onClick(View v) {
super.onClick(v);
int i = v.getId();
if (i == R.id.gotoanother) {
// 大小窗切换
/*if (currentState != CURRENT_STATE_NORMAL
&& currentState != CURRENT_STATE_PREPARING
&& currentState != CURRENT_STATE_AUTO_COMPLETE) {
if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
if (!backPress()) {
startWindowFullscreen();
}
} else {
if (!startWindowFullscreen()) {
backPress();
}
}
}*/
if (currentScreen == SCREEN_WINDOW_FULLSCREEN) {
if (mBottomLayout.getVisibility() == View.GONE) {
tinyBackImageView.setVisibility(View.VISIBLE);
mBottomLayout.setVisibility(View.VISIBLE);
startButton.setVisibility(View.VISIBLE);
} else {
tinyBackImageView.setVisibility(View.GONE);
mBottomLayout.setVisibility(View.GONE);
startButton.setVisibility(View.GONE);
}
}
} else if (i == R.id.back_tiny) {
handlerBack();
}
}
@Override
public void showWifiDialog() {
super.showWifiDialog();
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setMessage(getResources().getString(R.string.tips_not_wifi));
builder.setPositiveButton(getResources().getString(R.string.tips_not_wifi_confirm), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
startVideo();
WIFI_TIP_DIALOG_SHOWED = true;
}
});
builder.setNegativeButton(getResources().getString(R.string.tips_not_wifi_cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
}
@Override
public void onAutoCompletion() {
super.onAutoCompletion();
cancelDismissControlViewTimer();
}
@Override
public void onCompletion() {
if (thumbImageView != null) {
thumbImageView.setVisibility(GONE);
}
if (mBottomLayout != null) {
mBottomLayout.setVisibility(GONE);
}
super.onCompletion();
cancelDismissControlViewTimer();
}
/*
Attention
*/
/******************************下面的不是很重要*********************************/
@Override
public void setUiWitStateAndScreen(int state) {
super.setUiWitStateAndScreen(state);
switch (currentState) {
case CURRENT_STATE_NORMAL:
changeUiToNormal();
break;
case CURRENT_STATE_PREPARING:
changeUiToPreparingShow();
startDismissControlViewTimer();
break;
case CURRENT_STATE_PLAYING:
changeUiToPlayingShow();
startDismissControlViewTimer();
break;
case CURRENT_STATE_PAUSE:
changeUiToPauseShow();
cancelDismissControlViewTimer();
break;
case CURRENT_STATE_ERROR:
changeUiToError();
break;
case CURRENT_STATE_AUTO_COMPLETE:
changeUiToCompleteShow();
cancelDismissControlViewTimer();
bottomProgressBar.setProgress(100);
EventBus.getDefault().post(new MessageEvent(mUrl));// 播放完成 通知ChatActivity
break;
case CURRENT_STATE_PLAYING_BUFFERING_START:
changeUiToPlayingBufferingShow();
break;
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
super.onStartTrackingTouch(seekBar);
cancelDismissControlViewTimer();
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
super.onStopTrackingTouch(seekBar);
startDismissControlViewTimer();
}
public void startVideo() {
prepareMediaPlayer();
onEvent(JCUserActionStandard.ON_CLICK_START_THUMB);
}
public void onCLickUiToggleToClear() {
if (currentState == CURRENT_STATE_PREPARING) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToPreparingClear();
} else {
}
} else if (currentState == CURRENT_STATE_PLAYING) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToPlayingClear();
} else {
}
} else if (currentState == CURRENT_STATE_PAUSE) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToPauseClear();
} else {
}
} else if (currentState == CURRENT_STATE_AUTO_COMPLETE) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToCompleteClear();
} else {
}
} else if (currentState == CURRENT_STATE_PLAYING_BUFFERING_START) {
if (bottomContainer.getVisibility() == View.VISIBLE) {
changeUiToPlayingBufferingClear();
} else {
}
}
}
@Override
public void setProgressAndText() {
super.setProgressAndText();
int position = getCurrentPositionWhenPlaying();
int duration = getDuration();
int progress = position * 100 / (duration == 0 ? 1 : duration);
if (progress != 0)
bottomProgressBar.setProgress(progress);
}
@Override
public void setBufferProgress(int bufferProgress) {
super.setBufferProgress(bufferProgress);
if (bufferProgress != 0)
bottomProgressBar.setSecondaryProgress(bufferProgress);
}
@Override
public void resetProgressAndTime() {
super.resetProgressAndTime();
bottomProgressBar.setProgress(0);
bottomProgressBar.setSecondaryProgress(0);
}
//Unified management Ui
public void changeUiToNormal() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.VISIBLE, View.INVISIBLE, View.VISIBLE,
View.INVISIBLE, View.VISIBLE, View.VISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.VISIBLE, View.INVISIBLE, View.VISIBLE,
View.INVISIBLE, View.VISIBLE, View.VISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToPreparingShow() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.VISIBLE, View.INVISIBLE, View.INVISIBLE,
View.VISIBLE, View.VISIBLE, View.VISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.VISIBLE, View.INVISIBLE, View.INVISIBLE,
View.VISIBLE, View.VISIBLE, View.VISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToPreparingClear() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.VISIBLE, View.INVISIBLE, View.INVISIBLE,
View.VISIBLE, View.VISIBLE, View.VISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.VISIBLE, View.INVISIBLE, View.INVISIBLE,
View.VISIBLE, View.VISIBLE, View.VISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_TINY:
break;
}
}
//JustPreparedUi
@Override
public void onPrepared() {
super.onPrepared();
setAllControlsVisible(View.VISIBLE, View.INVISIBLE, View.INVISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.VISIBLE);
startDismissControlViewTimer();
}
public void changeUiToPlayingShow() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.VISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.VISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToPlayingClear() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.INVISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.VISIBLE);
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.INVISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.VISIBLE);
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToPauseShow() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.VISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.VISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToPauseClear() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.INVISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.INVISIBLE,
View.INVISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToPlayingBufferingShow() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.INVISIBLE,
View.VISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.INVISIBLE,
View.VISIBLE, View.INVISIBLE, View.INVISIBLE, View.INVISIBLE);
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToPlayingBufferingClear() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.INVISIBLE,
View.VISIBLE, View.INVISIBLE, View.INVISIBLE, View.VISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.INVISIBLE,
View.VISIBLE, View.INVISIBLE, View.INVISIBLE, View.VISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToCompleteShow() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.VISIBLE,
View.INVISIBLE, View.VISIBLE, View.INVISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.VISIBLE, View.VISIBLE, View.VISIBLE,
View.INVISIBLE, View.VISIBLE, View.INVISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToCompleteClear() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.VISIBLE,
View.INVISIBLE, View.VISIBLE, View.INVISIBLE, View.VISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.VISIBLE,
View.INVISIBLE, View.VISIBLE, View.INVISIBLE, View.VISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void changeUiToError() {
switch (currentScreen) {
case SCREEN_LAYOUT_NORMAL:
case SCREEN_LAYOUT_LIST:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.VISIBLE,
View.INVISIBLE, View.INVISIBLE, View.VISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_FULLSCREEN:
setAllControlsVisible(View.INVISIBLE, View.INVISIBLE, View.VISIBLE,
View.INVISIBLE, View.INVISIBLE, View.VISIBLE, View.INVISIBLE);
updateStartImage();
break;
case SCREEN_WINDOW_TINY:
break;
}
}
public void setAllControlsVisible(int topCon, int bottomCon, int startBtn, int loadingPro,
int thumbImg, int coverImg, int bottomPro) {
topContainer.setVisibility(topCon);
// bottomContainer.setVisibility(bottomCon);
startButton.setVisibility(startBtn);
loadingProgressBar.setVisibility(loadingPro);
loadingProgressBar.setVisibility(loadingPro);
thumbImageView.setVisibility(thumbImg);
// bottomProgressBar.setVisibility(bottomPro);
}
public void updateStartImage() {
if (currentState == CURRENT_STATE_PLAYING) {
startButton.setImageResource(R.drawable.jc_click_pause_selector);
} else if (currentState == CURRENT_STATE_ERROR) {
startButton.setImageResource(R.drawable.jc_click_error_selector);
} else {
startButton.setImageResource(R.drawable.jc_click_play_selector);
}
}
@Override
public 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.jc_dialog_progress, null);
mDialogProgressBar = ((ProgressBar) localView.findViewById(R.id.duration_progressbar));
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.jc_style_dialog_progress);
mProgressDialog.setContentView(localView);
mProgressDialog.getWindow().addFlags(Window.FEATURE_ACTION_BAR);
mProgressDialog.getWindow().addFlags(32);
mProgressDialog.getWindow().addFlags(16);
mProgressDialog.getWindow().setLayout(-2, -2);
WindowManager.LayoutParams localLayoutParams = mProgressDialog.getWindow().getAttributes();
localLayoutParams.gravity = Gravity.CENTER;
mProgressDialog.getWindow().setAttributes(localLayoutParams);
}
if (!mProgressDialog.isShowing()) {
mProgressDialog.show();
}
mDialogSeekTime.setText(seekTime);
mDialogTotalTime.setText(" / " + totalTime);
mDialogProgressBar.setProgress(totalTimeDuration <= 0 ? 0 : (seekTimePosition * 100 / totalTimeDuration));
if (deltaX > 0) {
mDialogIcon.setBackgroundResource(R.drawable.jc_forward_icon);
} else {
mDialogIcon.setBackgroundResource(R.drawable.jc_backward_icon);
}
onCLickUiToggleToClear();
}
@Override
public void dismissProgressDialog() {
super.dismissProgressDialog();
if (mProgressDialog != null) {
mProgressDialog.dismiss();
}
}
@Override
public void showVolumeDialog(float deltaY, int volumePercent) {
super.showVolumeDialog(deltaY, volumePercent);
if (mVolumeDialog == null) {
View localView = LayoutInflater.from(getContext()).inflate(R.layout.jc_dialog_volume, null);
mDialogVolumeImageView = ((ImageView) localView.findViewById(R.id.volume_image_tip));
mDialogVolumeTextView = ((TextView) localView.findViewById(R.id.tv_volume));
mDialogVolumeProgressBar = ((ProgressBar) localView.findViewById(R.id.volume_progressbar));
mVolumeDialog = new Dialog(getContext(), R.style.jc_style_dialog_progress);
mVolumeDialog.setContentView(localView);
mVolumeDialog.getWindow().addFlags(8);
mVolumeDialog.getWindow().addFlags(32);
mVolumeDialog.getWindow().addFlags(16);
mVolumeDialog.getWindow().setLayout(-2, -2);
WindowManager.LayoutParams localLayoutParams = mVolumeDialog.getWindow().getAttributes();
localLayoutParams.gravity = Gravity.CENTER;
mVolumeDialog.getWindow().setAttributes(localLayoutParams);
}
if (!mVolumeDialog.isShowing()) {
mVolumeDialog.show();
}
if (volumePercent <= 0) {
mDialogVolumeImageView.setBackgroundResource(R.drawable.jc_close_volume);
} else {
mDialogVolumeImageView.setBackgroundResource(R.drawable.jc_add_volume);
}
if (volumePercent > 100) {
volumePercent = 100;
} else if (volumePercent < 0) {
volumePercent = 0;
}
mDialogVolumeTextView.setText(volumePercent + "%");
mDialogVolumeProgressBar.setProgress(volumePercent);
onCLickUiToggleToClear();
}
@Override
public void dismissVolumeDialog() {
super.dismissVolumeDialog();
if (mVolumeDialog != null) {
mVolumeDialog.dismiss();
}
}
@Override
public void showBrightnessDialog(int brightnessPercent) {
super.showBrightnessDialog(brightnessPercent);
if (mBrightnessDialog == null) {
View localView = LayoutInflater.from(getContext()).inflate(R.layout.jc_dialog_brightness, null);
mDialogBrightnessTextView = ((TextView) localView.findViewById(R.id.tv_brightness));
mDialogBrightnessProgressBar = ((ProgressBar) localView.findViewById(R.id.brightness_progressbar));
mBrightnessDialog = new Dialog(getContext(), R.style.jc_style_dialog_progress);
mBrightnessDialog.setContentView(localView);
mBrightnessDialog.getWindow().addFlags(Window.FEATURE_ACTION_BAR);
mBrightnessDialog.getWindow().addFlags(32);
mBrightnessDialog.getWindow().addFlags(16);
mBrightnessDialog.getWindow().setLayout(-2, -2);
WindowManager.LayoutParams localLayoutParams = mBrightnessDialog.getWindow().getAttributes();
localLayoutParams.gravity = Gravity.CENTER;
mBrightnessDialog.getWindow().setAttributes(localLayoutParams);
}
if (!mBrightnessDialog.isShowing()) {
mBrightnessDialog.show();
}
if (brightnessPercent > 100) {
brightnessPercent = 100;
} else if (brightnessPercent < 0) {
brightnessPercent = 0;
}
mDialogBrightnessTextView.setText(brightnessPercent + "%");
mDialogBrightnessProgressBar.setProgress(brightnessPercent);
onCLickUiToggleToClear();
}
@Override
public void dismissBrightnessDialog() {
super.dismissBrightnessDialog();
if (mBrightnessDialog != null) {
mBrightnessDialog.dismiss();
}
}
public void startDismissControlViewTimer() {
cancelDismissControlViewTimer();
DISMISS_CONTROL_VIEW_TIMER = new Timer();
mDismissControlViewTimerTask = new DismissControlViewTimerTask();
DISMISS_CONTROL_VIEW_TIMER.schedule(mDismissControlViewTimerTask, 2500);
}
public void cancelDismissControlViewTimer() {
if (DISMISS_CONTROL_VIEW_TIMER != null) {
DISMISS_CONTROL_VIEW_TIMER.cancel();
}
if (mDismissControlViewTimerTask != null) {
mDismissControlViewTimerTask.cancel();
}
}
public class DismissControlViewTimerTask extends TimerTask {
@Override
public void run() {
if (currentState != CURRENT_STATE_NORMAL
&& currentState != CURRENT_STATE_ERROR
&& currentState != CURRENT_STATE_AUTO_COMPLETE) {
if (getContext() != null && getContext() instanceof Activity) {
((Activity) getContext()).runOnUiThread(new Runnable() {
@Override
public void run() {
bottomContainer.setVisibility(View.INVISIBLE);
topContainer.setVisibility(View.INVISIBLE);
startButton.setVisibility(View.INVISIBLE);
if (currentScreen != SCREEN_WINDOW_TINY) {
// bottomProgressBar.setVisibility(View.VISIBLE);
}
}
});
}
}
}
}
}
package fm.jiecao.jcvideoplayer_lib;
/**
* Created by Administrator on 2017/3/17 0017.
* 1. 视频播放控件 已准备,通知朋友圈页面停止播放录音,防止同时播放两种声音
* 2. 我的同事 其他页面调用api成功,通知同事页面刷新UI
* 3. 消息群发 收到回执后,通知群发页面,当群发页面收到所有人回执时,在隐藏等待符
* 4. 视频播放完成,通知单聊界面,判断是否为阅后即焚视频
*/
public class MessageEvent {
public final String message;
public MessageEvent(String message) {
this.message = message;
}
}
\ No newline at end of file
package fm.jiecao.jcvideoplayer_lib;
/**
* Created by xuan 改进jcv的通知回调方式
* On 2016/04/04 22:13
*/
public interface OnJcvdListener {
void onPrepared(); // 加载完成的回调
void onCompletion(); // 播放完成的回调
void onError(); // 播放出错
void onPause(); // 播放暂停
void onReset(); // 重置播放器
}
package fm.jiecao.jcvideoplayer_lib;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
public class SavaVideoDialog extends Dialog implements View.OnClickListener {
private TextView tv1;
private OnSavaVideoDialogClickListener mOnSavaVideoDialogClickListener;
public SavaVideoDialog(Context context, OnSavaVideoDialogClickListener mOnSavaVideoDialogClickListener) {
super(context, R.style.BottomDialog);
this.mOnSavaVideoDialogClickListener = mOnSavaVideoDialogClickListener;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialog_sava_video);
setCanceledOnTouchOutside(true);
initView();
}
private void initView() {
tv1 = (TextView) findViewById(R.id.tv1);
tv1.setOnClickListener(this);
Window o = getWindow();
WindowManager.LayoutParams lp = o.getAttributes();
// x/y坐标
// lp.x = 100;
// lp.y = 100;
lp.width = ScreenUtil.getScreenWidth(getContext());
o.setAttributes(lp);
this.getWindow().setGravity(Gravity.BOTTOM);
this.getWindow().setWindowAnimations(R.style.BottomDialog_Animation);
}
@Override
public void onClick(View v) {
int i = v.getId();
if (i == R.id.tv1) {
mOnSavaVideoDialogClickListener.tv1Click();
}
}
public interface OnSavaVideoDialogClickListener {
void tv1Click();
}
}
package fm.jiecao.jcvideoplayer_lib;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.WindowManager;
/**
* Created by zq on 2017/9/19 0019.
*/
public class ScreenUtil {
private ScreenUtil() {
/* cannot be instantiated */
throw new UnsupportedOperationException("cannot be instantiated");
}
/**
* 获取屏幕宽度
*/
public static int getScreenWidth(Context context) {
WindowManager wm = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(outMetrics);
return outMetrics.widthPixels;
}
/**
* 获取屏幕高度
*/
public static int getScreenHeight(Context context) {
WindowManager wm = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
DisplayMetrics outMetrics = new DisplayMetrics();
wm.getDefaultDisplay().getMetrics(outMetrics);
return outMetrics.heightPixels;
}
/**
* 获取状态栏的高度
*/
public static int getStatusHeight(Context context) {
int statusHeight = -1;
try {
Class<?> clazz = Class.forName("com.android.internal.R$dimen.xml");
Object object = clazz.newInstance();
int height = Integer.parseInt(clazz.getField("status_bar_height")
.get(object).toString());
statusHeight = context.getResources().getDimensionPixelSize(height);
} catch (Exception e) {
e.printStackTrace();
}
return statusHeight;
}
/**
* 获取当前屏幕截图,包含状态栏
*/
public static Bitmap snapShotWithStatusBar(Activity activity) {
View view = activity.getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bmp = view.getDrawingCache();
int width = getScreenWidth(activity);
int height = getScreenHeight(activity);
Bitmap bitmap = null;
bitmap = Bitmap.createBitmap(bmp, 0, 0, width, height);
view.destroyDrawingCache();
return bitmap;
}
/**
* 获取当前屏幕截图,不包含状态栏
*/
public static Bitmap snapShotWithoutStatusBar(Activity activity) {
View view = activity.getWindow().getDecorView();
view.setDrawingCacheEnabled(true);
view.buildDrawingCache();
Bitmap bmp = view.getDrawingCache();
Rect frame = new Rect();
activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
int statusBarHeight = frame.top;
int width = getScreenWidth(activity);
int height = getScreenHeight(activity);
Bitmap bitmap = null;
bitmap = Bitmap.createBitmap(bmp, 0, statusBarHeight, width, height - statusBarHeight);
view.destroyDrawingCache();
return bitmap;
}
}
package fm.jiecao.jcvideoplayer_lib;
import android.util.Log;
/**
* create by xuan 抖音视频管理器
*/
public class VideotillManager {
private static VideotillManager mVideotillManager;
private JCVideoViewbyXuan mVideo;
private VideotillManager() {
}
public static VideotillManager instance() {
if (mVideotillManager == null) {
mVideotillManager = new VideotillManager();
}
return mVideotillManager;
}
public void addVideoPlay(JCVideoViewbyXuan video) {
mVideo = video;
}
public void releaseVideo() {
if (mVideo != null) {
mVideo.reset();
mVideo = null;
}
}
public void play() {
if (mVideo != null) {
Log.e("xuan", "VideotillManager play: ");
mVideo.play("");
}
}
public void pause() {
Log.e("xuan", "VideotillManager pause: ");
if (mVideo != null && mVideo.isPlaying()) {
mVideo.pause();
}
}
}
package fm.jiecao.jcvideoplayer_lib;
import java.io.File;
import java.net.URL;
import java.net.URLConnection;
/**
* Created by dty on 2015/11/8.
*/
public class downloadTask extends Thread {
String urlStr, threadNo, fileName;
private int blockSize, downloadSizeMore;
private int threadNum = 5;
private int mDownloadedSize = 0;
private int fileSize = 0;
public downloadTask(String urlStr, int threadNum, String fileName) {
this.urlStr = urlStr;
this.threadNum = threadNum;
this.fileName = fileName;
}
/**
* @修改人:TanX
* @时间: 2016/4/19 17:22
* @参数:
* @说明: 这里会出现资源站没有该资源,而下载却一直在下载的情况,所以加个时间做超时
* 如果超过10秒下载的量依然没变,则超时
**/
@Override
public void run() {
FileDownloadThread[] fds = new FileDownloadThread[threadNum];
int overTime = 10000;//10秒超时
int downloadSize = 0;//初始下载为0
long downloadTime = System.currentTimeMillis();//起始下载时间
try {
// TanX.Log("开始下载,URL:" + urlStr);
URL url = new URL(urlStr);
URLConnection conn = url.openConnection();
//获取下载文件的总大小
fileSize = conn.getContentLength();
//计算每个线程要下载的数据量
blockSize = fileSize / threadNum;
// 解决整除后百分比计算误差
downloadSizeMore = (fileSize % threadNum);
File file = new File(fileName);
for (int i = 0; i < threadNum; i++) {
//启动线程,分别下载自己需要下载的部分
FileDownloadThread fdt = new FileDownloadThread(url, file,
i * blockSize, (i + 1) * blockSize - 1);
fdt.setName("Thread" + i);
fdt.start();
fds[i] = fdt;
}
boolean finished = false;
while (!finished) {
// TanX.Log("下载中");
if (System.currentTimeMillis() - downloadTime >= overTime) {
//到了超时的时限
if (mDownloadedSize <= downloadSize) {
// TanX.Log("总下载大小:" + mDownloadedSize);
//过了10秒,但是并没下载到东西,超时
throw new Exception();
}
//下载到了东西
downloadTime = System.currentTimeMillis();//重置时间
downloadSize = mDownloadedSize;//设置为当前的下载量
}
// 先把整除的余数搞定
mDownloadedSize = downloadSizeMore;
finished = true;
for (int i = 0; i < fds.length; i++) {
mDownloadedSize += fds[i].getDownloadSize();
if (!fds[i].isFinished()) {
finished = false;
}
}
}
// TanX.Log("下载完成");
} catch (Exception e) {
// TanX.Log("下载异常");
e.printStackTrace();
}
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<rotate
android:duration="5"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="-2" />
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<rotate
android:duration="20"
android:fromDegrees="-2"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="0" />
</set>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXDelta="0"
android:fromYDelta="100%"
android:toXDelta="0"
android:toYDelta="0">
</translate>
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="0"
android:toYDelta="100%">
</translate>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners
android:bottomLeftRadius="0dp"
android:bottomRightRadius="0dp"
android:topLeftRadius="9dp"
android:topRightRadius="9dp" />
<solid android:color="@android:color/white" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<solid android:color="#a5ffffff" />
<size android:height="4.0dip" />
<corners android:radius="1.0dip" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<solid android:color="#ffe0e0e0" />
<size android:height="4.0dip" />
<corners android:radius="1.0dip" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<solid android:color="#fff85959" />
<size android:height="4.0dip" />
<corners android:radius="1.0dip" />
</shape>
</clip>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<solid android:color="#a5ffffff" />
<size android:height="1.0dip" />
<corners android:radius="1.5dip" />
</shape>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<solid android:color="#ffffffff" />
<size android:height="1.0dip" />
<corners android:radius="1.5dip" />
</shape>
</clip>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<solid android:color="#fff85959" />
<size android:height="1.0dip" />
<corners android:radius="1.5dip" />
</shape>
</clip>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/jc_seek_thumb_pressed" android:state_pressed="true" />
<item android:drawable="@drawable/jc_seek_thumb_normal" />
</selector>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/jc_back_pressed" android:state_pressed="true" />
<item android:drawable="@drawable/jc_back_normal" />
</selector>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/jc_back_tiny_pressed" android:state_pressed="true" />
<item android:drawable="@drawable/jc_back_tiny_normal" />
</selector>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/jc_error_pressed" android:state_pressed="true" />
<item android:drawable="@drawable/jc_error_normal" />
</selector>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/jc_pause_pressed" android:state_pressed="true" />
<item android:drawable="@drawable/jc_pause_normal" />
</selector>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/jc_play_pressed" android:state_pressed="true" />
<item android:drawable="@drawable/jc_play_normal" />
</selector>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<solid android:color="#ffffffff" />
<corners android:radius="2dp" />
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<solid android:color="#fff85959" />
<corners android:radius="2dp" />
</shape>
</clip>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#cc000000" />
<corners
android:bottomLeftRadius="6.0dip"
android:bottomRightRadius="6.0dip"
android:topLeftRadius="6.0dip"
android:topRightRadius="6.0dip" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/jc_loading_bg"
android:fromDegrees="0.0"
android:pivotX="50.0%"
android:pivotY="50.0%"
android:toDegrees="360.0" />
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="oval"
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffffff" />
<size
android:height="15.0dip"
android:width="15.0dip" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape android:shape="oval"
xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#fff0f0f0" />
<size
android:height="15.0dip"
android:width="15.0dip" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<solid android:color="#ffffffff" />
<corners android:radius="2.0dip" />
</shape>
</item>
<item android:id="@android:id/progress">
<clip
android:clipOrientation="vertical"
android:gravity="bottom">
<shape>
<solid android:color="#fff85959" />
<corners android:radius="2.0dip" />
</shape>
</clip>
</item>
</layer-list>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_for_shatup"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/tv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="20dp"
android:paddingTop="20dp"
android:text="@string/sava_video"
android:textColor="@color/black"
android:textSize="15dp" />
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/jc_dialog_progress_bg"
android:orientation="vertical">
<LinearLayout
android:layout_width="155dp"
android:layout_height="120dp"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:src="@drawable/jc_brightness_video" />
<TextView
android:id="@+id/tv_brightness"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="12dp"
android:gravity="center_horizontal"
android:textColor="#ffffffff"
android:textSize="16sp" />
<ProgressBar
android:id="@+id/brightness_progressbar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="3dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginTop="8dp"
android:max="100"
android:progressDrawable="@drawable/jc_dialog_progress" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/jc_dialog_progress_bg"
android:orientation="vertical">
<LinearLayout
android:layout_width="152dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/duration_image_tip"
android:layout_width="36dp"
android:layout_height="27dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_current"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#fff85959"
android:textSize="14sp" />
<TextView
android:id="@+id/tv_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffffff"
android:textSize="14sp" />
</LinearLayout>
<ProgressBar
android:id="@+id/duration_progressbar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="4dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
android:max="100"
android:progressDrawable="@drawable/jc_dialog_progress" />
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/jc_dialog_progress_bg"
android:orientation="vertical">
<LinearLayout
android:layout_width="155dp"
android:layout_height="120dp"
android:orientation="vertical">
<ImageView
android:id="@+id/volume_image_tip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp" />
<TextView
android:id="@+id/tv_volume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="12dp"
android:gravity="center_horizontal"
android:textColor="#ffffffff"
android:textSize="16sp" />
<ProgressBar
android:id="@+id/volume_progressbar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="3dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginTop="8dp"
android:max="100"
android:progressDrawable="@drawable/jc_dialog_progress" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black">
<FrameLayout
android:id="@+id/surface_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<LinearLayout
android:id="@+id/layout_bottom"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:background="#99000000"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:id="@+id/current"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:text="00:00"
android:textColor="#ffffff" />
<SeekBar
android:id="@+id/bottom_seek_progress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1.0"
android:background="@null"
android:max="100"
android:maxHeight="4dp"
android:minHeight="4dp"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:progressDrawable="@drawable/jc_bottom_seek_progress"
android:thumb="@drawable/jc_bottom_seek_thumb" />
<TextView
android:id="@+id/total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"
android:text="00:00"
android:textColor="#ffffff" />
<ImageView
android:id="@+id/fullscreen"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingRight="16dp"
android:scaleType="center"
android:src="@drawable/jc_enlarge" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout_top"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@drawable/jc_title_bg"
android:gravity="center_vertical"
android:orientation="horizontal">
</LinearLayout>
<ProgressBar
android:id="@+id/loading"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminateDrawable="@drawable/jc_loading"
android:visibility="invisible" />
<ImageView
android:id="@+id/start"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:src="@drawable/jc_click_play_selector" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:descendantFocusability="blocksDescendants">
<FrameLayout
android:id="@+id/surface_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<ImageView
android:id="@+id/thumb"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#000000"
android:scaleType="centerCrop"/>
<LinearLayout
android:id="@+id/layout_top"
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center_vertical"
android:visibility="gone">
<ImageView
android:id="@+id/back"
android:layout_width="23dp"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:paddingLeft="14dp"
android:scaleType="centerInside"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:textColor="@android:color/white"
android:textSize="18sp"/>
</LinearLayout>
<ImageView
android:id="@+id/gotoanother"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/back_tiny"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_marginTop="24dp"
android:padding="9dp"
android:src="@drawable/jc_back_tiny_normal"
android:visibility="visible"/>
<ProgressBar
android:id="@+id/loading"
android:layout_width="@dimen/jc_start_button_w_h_normal"
android:layout_height="@dimen/jc_start_button_w_h_normal"
android:layout_centerInParent="true"
android:indeterminateDrawable="@drawable/jc_loading"
android:visibility="visible"/>
<ImageView
android:id="@+id/start"
android:layout_width="@dimen/jc_start_button_w_h_normal"
android:layout_height="@dimen/jc_start_button_w_h_normal"
android:layout_centerInParent="true"
android:src="@drawable/jc_click_play_selector"/>
<LinearLayout
android:id="@+id/layout_bottom"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:background="@drawable/jc_bottom_bg"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="gone">
<TextView
android:id="@+id/current"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:text="00:00"
android:textColor="#ffffff"
android:textSize="13dp"/>
<SeekBar
android:id="@+id/bottom_seek_progress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1.0"
android:background="@null"
android:max="100"
android:maxHeight="1.0dip"
android:minHeight="1.0dip"
android:progressDrawable="@drawable/jc_bottom_seek_progress"
android:thumb="@drawable/jc_bottom_seek_thumb"/>
<TextView
android:id="@+id/total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="14dp"
android:text="00:00"
android:textColor="#ffffff"
android:textSize="13sp"/>
<ImageView
android:id="@+id/fullscreen"
android:layout_width="24.5dp"
android:layout_height="fill_parent"
android:layout_marginLeft="14.0dip"
android:layout_marginRight="14.0dip"
android:scaleType="centerInside"
android:src="@drawable/jc_enlarge"
android:visibility="gone"/>
</LinearLayout>
</RelativeLayout>
<ProgressBar
android:id="@+id/bottom_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="1.5dp"
android:layout_alignParentBottom="true"
android:max="100"
android:progressDrawable="@drawable/jc_bottom_progress"
android:visibility="gone"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:descendantFocusability="blocksDescendants">
<FrameLayout
android:id="@+id/surface_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<ImageView
android:id="@+id/thumb"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#000000"
android:scaleType="centerCrop"/>
<LinearLayout
android:id="@+id/layout_bottom"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="@drawable/jc_bottom_bg"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="invisible">
<TextView
android:id="@+id/current"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:text="00:00"
android:textColor="#ffffff"/>
<SeekBar
android:id="@+id/bottom_seek_progress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1.0"
android:background="@null"
android:max="100"
android:maxHeight="1.0dip"
android:minHeight="1.0dip"
android:paddingBottom="8dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingTop="8dp"
android:progressDrawable="@drawable/jc_bottom_seek_progress"
android:thumb="@drawable/jc_bottom_seek_thumb"/>
<TextView
android:id="@+id/total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00:00"
android:textColor="#ffffff"/>
<ImageView
android:id="@+id/fullscreen"
android:layout_width="24.5dp"
android:layout_height="fill_parent"
android:layout_marginLeft="14.0dip"
android:layout_marginRight="14.0dip"
android:scaleType="centerInside"
android:src="@drawable/jc_enlarge"/>
</LinearLayout>
<ProgressBar
android:id="@+id/bottom_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="1.5dp"
android:layout_alignParentBottom="true"
android:max="100"
android:progressDrawable="@drawable/jc_bottom_progress"/>
<ImageView
android:id="@+id/back_tiny"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginLeft="6dp"
android:layout_marginTop="6dp"
android:background="@drawable/jc_click_back_tiny_selector"
android:visibility="visible"/>
<LinearLayout
android:id="@+id/layout_top"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@drawable/jc_title_bg"
android:gravity="center_vertical">
<ImageView
android:id="@+id/back"
android:layout_width="23dp"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:paddingLeft="14dp"
android:scaleType="centerInside"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:textColor="@android:color/white"
android:textSize="18sp"/>
</LinearLayout>
<ProgressBar
android:id="@+id/loading"
android:layout_width="@dimen/jc_start_button_w_h_normal"
android:layout_height="@dimen/jc_start_button_w_h_normal"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminateDrawable="@drawable/jc_loading"
android:visibility="invisible"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/gotoanother"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"/>
<ImageView
android:id="@+id/start"
android:layout_width="@dimen/jc_start_button_w_h_normal"
android:layout_height="@dimen/jc_start_button_w_h_normal"
android:layout_alignLeft="@+id/loading"
android:layout_alignStart="@+id/loading"
android:layout_alignTop="@+id/loading"
android:layout_gravity="center"
android:src="@drawable/jc_click_play_selector"/>
</FrameLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:descendantFocusability="blocksDescendants">
<FrameLayout
android:id="@+id/surface_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<ImageView
android:id="@+id/thumb"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#000000"
android:scaleType="fitXY"/>
<LinearLayout
android:id="@+id/layout_bottom"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="@drawable/jc_bottom_bg"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="invisible">
<TextView
android:id="@+id/current"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:text="00:00"
android:textColor="#ffffff"/>
<SeekBar
android:id="@+id/bottom_seek_progress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1.0"
android:background="@null"
android:max="100"
android:maxHeight="1.0dip"
android:minHeight="1.0dip"
android:paddingBottom="8dp"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:paddingTop="8dp"
android:progressDrawable="@drawable/jc_bottom_seek_progress"
android:thumb="@drawable/jc_bottom_seek_thumb"/>
<TextView
android:id="@+id/total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00:00"
android:textColor="#ffffff"/>
<ImageView
android:id="@+id/fullscreen"
android:layout_width="24.5dp"
android:layout_height="fill_parent"
android:layout_marginLeft="14.0dip"
android:layout_marginRight="14.0dip"
android:scaleType="centerInside"
android:src="@drawable/jc_enlarge"/>
</LinearLayout>
<ProgressBar
android:id="@+id/bottom_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="1.5dp"
android:layout_alignParentBottom="true"
android:max="100"
android:progressDrawable="@drawable/jc_bottom_progress"/>
<ImageView
android:id="@+id/back_tiny"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginLeft="6dp"
android:layout_marginTop="6dp"
android:background="@drawable/jc_click_back_tiny_selector"
android:visibility="visible"/>
<LinearLayout
android:id="@+id/layout_top"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@drawable/jc_title_bg"
android:gravity="center_vertical">
<ImageView
android:id="@+id/back"
android:layout_width="23dp"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:paddingLeft="14dp"
android:scaleType="centerInside"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:textColor="@android:color/white"
android:textSize="18sp"/>
</LinearLayout>
<ProgressBar
android:id="@+id/loading"
android:layout_width="@dimen/jc_start_button_w_h_normal"
android:layout_height="@dimen/jc_start_button_w_h_normal"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:indeterminateDrawable="@drawable/jc_loading"
android:visibility="invisible"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<ImageView
android:id="@+id/start"
android:layout_width="@dimen/jc_start_button_w_h_normal"
android:layout_height="@dimen/jc_start_button_w_h_normal"
android:layout_alignLeft="@+id/loading"
android:layout_alignStart="@+id/loading"
android:layout_alignTop="@+id/loading"
android:layout_gravity="center"
android:src="@drawable/jc_click_play_selector"/>
</FrameLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="tips_not_wifi">Você está usando a rede móvel, você deseja mesmo ver o video?</string>
<string name="tips_not_wifi_confirm">Continuar</string>
<string name="tips_not_wifi_cancel">Parar</string>
<string name="no_url">Sem Vídeo</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="tips_not_wifi">Şu anda mobil veriyi kullanıyorsunuz, yüksek veri kaybına yol açabilir</string>
<string name="tips_not_wifi_confirm">Devam Et</string>
<string name="tips_not_wifi_cancel">Durdur</string>
<string name="no_url">URL Bulunamadı</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="tips_not_wifi">您當前正在使用移動網絡,繼續播放將消耗流量</string>
<string name="tips_not_wifi_confirm">繼續播放</string>
<string name="tips_not_wifi_cancel">停止播放</string>
<string name="no_url">播放地址無效</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="tips_not_wifi">您當前正在使用移動網絡,繼續播放將消耗流量</string>
<string name="tips_not_wifi_confirm">繼續播放</string>
<string name="tips_not_wifi_cancel">停止播放</string>
<string name="no_url">播放地址無效</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="tips_not_wifi">您当前正在使用移动网络,继续播放将消耗流量</string>
<string name="tips_not_wifi_confirm">继续播放</string>
<string name="tips_not_wifi_cancel">停止播放</string>
<string name="no_url">播放地址无效</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="ChatImageView">
<attr name="chat_direction" format="boolean"/>
</declare-styleable>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="black">#323232</color>
<color name="transparent">#00000000</color>
</resources>
<resources>
<dimen name="jc_start_button_w_h_normal">32dp</dimen>
<dimen name="jc_start_button_w_h_fullscreen">32dp</dimen>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="tips_not_wifi">You are currently using the mobile network, the player will continue to consume traffic</string>
<string name="tips_not_wifi_confirm">Resume</string>
<string name="tips_not_wifi_cancel">Stop play</string>
<string name="no_url">No mUrl</string>
<string name="sava_video">保存视频</string>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="jc_style_dialog_progress" parent="@android:style/Theme.Dialog">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowAnimationStyle">@style/jc_popup_toast_anim</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
<style name="jc_popup_toast_anim" parent="@android:style/Animation">
<item name="android:windowEnterAnimation">@android:anim/fade_in</item>
<item name="android:windowExitAnimation">@android:anim/fade_out</item>
</style>
<style name="jc_vertical_progressBar">
<item name="android:maxWidth">12dp</item>
<item name="android:indeterminateOnly">false</item>
<item name="android:indeterminateDrawable">
@android:drawable/progress_indeterminate_horizontal
</item>
<item name="android:progressDrawable">@drawable/jc_volume_progress_bg</item>
<item name="android:indeterminateDuration">3500</item>
<item name="android:indeterminateBehavior">repeat</item>
<item name="android:minWidth">1dp</item>
</style>
<style name="BottomDialog.Animation" parent="Animation.AppCompat.Dialog">
<item name="android:windowEnterAnimation">@anim/translate_dialog_in</item>
<item name="android:windowExitAnimation">@anim/translate_dialog_out</item>
</style>
<style name="BottomDialog" parent="@style/Base.V7.Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@color/transparent</item>
</style>
</resources>
......@@ -5,6 +5,19 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
flavorDimensions "default"
}
productFlavors {
//开发环境
dev {
}
sit {
}
pro {
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment