diff --git a/.gitignore b/.gitignore index c88a4b635..2c7f378a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +gradle.properties *.iml .gradle /local.properties @@ -5,3 +6,4 @@ .DS_Store /build /captures +*.asc diff --git a/README.md b/README.md index 457627c6e..b6913f698 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,11 @@ 真正实现Android的全屏功能,励志成为Android平台使用最广泛的视频播放控件 ##使用 +引入类库 +```java +compile 'fm.jiecao:jiecaovideoplayer:1.2_preview' +``` + 添加布局 ```html - + diff --git a/app/src/test/java/fm/jiecao/jiecaovideoplayer/ExampleUnitTest.java b/app/src/test/java/fm/jiecao/jiecaovideoplayer/ExampleUnitTest.java index cf80a2ee1..2a4a2cd11 100644 --- a/app/src/test/java/fm/jiecao/jiecaovideoplayer/ExampleUnitTest.java +++ b/app/src/test/java/fm/jiecao/jiecaovideoplayer/ExampleUnitTest.java @@ -2,7 +2,7 @@ import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; /** * To work on unit tests, switch the Test Artifact in the Build Variants view. diff --git a/gradle.properties b/gradle.properties deleted file mode 100644 index 89e0d99e2..000000000 --- a/gradle.properties +++ /dev/null @@ -1,18 +0,0 @@ -# Project-wide Gradle settings. - -# IDE (e.g. Android Studio) users: -# Gradle settings configured through the IDE *will override* -# any settings specified in this file. - -# For more details on how to configure your build environment visit -# http://www.gradle.org/docs/current/userguide/build_environment.html - -# Specifies the JVM arguments used for the daemon process. -# The setting is particularly useful for tweaking memory settings. -# Default value: -Xmx10248m -XX:MaxPermSize=256m -# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 - -# When configured, Gradle will run in incubating parallel mode. -# This option should only be used with decoupled projects. More details, visit -# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects -# org.gradle.parallel=true diff --git a/gradle/maven_push.gradle b/gradle/maven_push.gradle new file mode 100644 index 000000000..ebe211ed9 --- /dev/null +++ b/gradle/maven_push.gradle @@ -0,0 +1,93 @@ +apply plugin: 'maven' +apply plugin: 'signing' + +//task javadocJar(type: Jar) { +// classifier = 'javadoc' +// from javadoc +//} +// +//task sourcesJar(type: Jar) { +// classifier = 'sources' +// from sourceSets.main.allSource +//} + +//artifacts { +// archives file('../downloads/jiecao-videoplayer-1.2preview.aar') +//} + +signing { + sign configurations.archives +} + +group = "fm.jiecao" +archivesBaseName = "jiecaovideoplayer" +version = "1.2" + +uploadArchives { + repositories { + mavenDeployer { + beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } + + repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { + authentication(userName: ossrhUsername, password: ossrhPassword) + } + + snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { + authentication(userName: ossrhUsername, password: ossrhPassword) + } + + pom.project { + name 'jiecaovideoplayer' + packaging 'jar' + // optionally artifactId can be defined here + description 'android videoplayer videoview 安卓视频播放器 全屏 播放器列表全屏 仿今日头条UI' + url 'https://github.com/lipangit/jiecaovideoplayer' + + scm { + connection 'https://github.com/lipangit/jiecaovideoplayer' + developerConnection 'https://github.com/lipangit/jiecaovideoplayer' + url 'https://github.com/lipangit/jiecaovideoplayer' + } + + licenses { + license { + name 'MIT' + url 'http://mit-license.org/' + } + } + + developers { + developer { + id 'Nathen' + name 'Nathen' + email 'lipan@jiecao.fm' + } + } + } + } + } +} + +task androidJavadocs(type: Javadoc) { + source = android.sourceSets.main.java.srcDirs + options { + encoding = "UTF-8" + } + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) +} + +task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) { + classifier = 'javadoc' + from androidJavadocs.destinationDir +} + +task androidSourcesJar(type: Jar) { + classifier = 'sources' + from android.sourceSets.main.java.srcDirs +} + +artifacts { + archives androidSourcesJar + archives androidJavadocsJar +} + diff --git a/jcvideoplayer-lib/build.gradle b/jcvideoplayer-lib/build.gradle index 5b5ec46ae..9af1ef422 100644 --- a/jcvideoplayer-lib/build.gradle +++ b/jcvideoplayer-lib/build.gradle @@ -7,8 +7,8 @@ android { defaultConfig { minSdkVersion 14 targetSdkVersion 23 - versionCode 12 - versionName "1.2_preview" + versionCode 13 + versionName "1.2" } buildTypes { release { @@ -28,3 +28,5 @@ dependencies { compile 'de.greenrobot:eventbus:2.4.0' compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4' } + +apply from: '../gradle/maven_push.gradle' diff --git a/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/FullScreenActivity.java b/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/FullScreenActivity.java index bce70d114..4be7c9c48 100644 --- a/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/FullScreenActivity.java +++ b/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/FullScreenActivity.java @@ -16,10 +16,7 @@ * On 2015/12/01 11:17 */ public class FullScreenActivity extends Activity { - /** - * TODO 可能有需求直接进入全屏,退出就退出播放,没有非全屏的需求 - * state是当前的播放状态,全屏之后要继续原来的状态 - */ + public static void toActivity(Context context, int state, String url, String thumb, String title) { STATE = state; URL = url; @@ -47,7 +44,7 @@ protected void onCreate(Bundle savedInstanceState) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); setContentView(R.layout.activity_fullscreen); jcVideoPlayer = (JCVideoPlayer) findViewById(R.id.jcvideoplayer); - jcVideoPlayer.setUpForFullscreen(URL, THUMB, TITLE, true); + jcVideoPlayer.setUpForFullscreen(URL, THUMB, TITLE); jcVideoPlayer.setState(STATE); JCMediaPlayer.intance().setUuid(jcVideoPlayer.uuid); manualQuit = false; diff --git a/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCVideoPlayer.java b/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCVideoPlayer.java index 07a883c53..0177d9587 100644 --- a/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCVideoPlayer.java +++ b/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/JCVideoPlayer.java @@ -2,9 +2,6 @@ import android.app.Activity; import android.content.Context; -import android.graphics.Bitmap; -import android.graphics.Color; -import android.graphics.drawable.ColorDrawable; import android.text.TextUtils; import android.util.AttributeSet; import android.util.Log; @@ -20,13 +17,8 @@ import android.widget.TextView; import android.widget.Toast; -import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; -import com.nostra13.universalimageloader.core.assist.ImageScaleType; -import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer; -import java.util.Formatter; -import java.util.Locale; import java.util.Timer; import java.util.TimerTask; import java.util.UUID; @@ -34,11 +26,13 @@ import de.greenrobot.event.EventBus; /** - * Created by Nathen + * @see 节操视频播放器 Github + *
* On 2015/11/30 11:59 */ public class JCVideoPlayer extends FrameLayout implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, SurfaceHolder.Callback, View.OnTouchListener { + //控件 ImageView ivStart; ProgressBar pbLoading, pbBottom; ImageView ivFullScreen; @@ -54,20 +48,15 @@ public class JCVideoPlayer extends FrameLayout implements View.OnClickListener, LinearLayout llTitleContainer; ImageView ivCover; - //这个组件的四个属性 - public String url; - public String thumb; - public String title; - public boolean ifFullScreen = false; + //属性 + private String url; + private String thumb; + private String title; + private boolean ifFullScreen = false; public String uuid;//区别相同地址,包括全屏和不全屏,和都不全屏时的相同地址 - - /** - * 是否显示标题 - */ public boolean ifShowTitle = false; - /** - * 为了保证全屏和退出全屏之后的状态和之前一样 - */ + + // 为了保证全屏和退出全屏之后的状态和之前一样,需要记录状态 public int CURRENT_STATE = -1;//-1相当于null public static final int CURRENT_STATE_PREPAREING = 0; public static final int CURRENT_STATE_PAUSE = 1; @@ -80,6 +69,11 @@ public class JCVideoPlayer extends FrameLayout implements View.OnClickListener, private static long clickfullscreentime; private static final int FULL_SCREEN_NORMAL_DELAY = 5000; + // 一些临时表示状态的变量 + private boolean touchingProgressBar = false; + boolean isFromFullScreenBackHere = false;//如果是true表示这个正在不是全屏,并且全屏刚推出,总之进入过全屏 + boolean isClickFullscreen = false; + public JCVideoPlayer(Context context, AttributeSet attrs) { super(context, attrs); uuid = UUID.randomUUID().toString(); @@ -121,14 +115,23 @@ private void init(Context context) { } /** - * 设置 + * 配置要播放的内容 + * + * @param url 视频地址 + * @param thumb 缩略图地址 + * @param title 标题 */ public void setUp(String url, String thumb, String title) { setUp(url, thumb, title, true); } /** - * @param ifShowTitle 是否显示标题 + * 配置要播放的内容 + * + * @param url 视频地址 + * @param thumb 缩略图地址 + * @param title 标题 + * @param ifShowTitle 是否在非全屏下显示标题 */ public void setUp(String url, String thumb, String title, boolean ifShowTitle) { setIfShowTitle(ifShowTitle); @@ -148,7 +151,7 @@ public void setUp(String url, String thumb, String title, boolean ifShowTitle) { ivStart.setVisibility(View.VISIBLE); llBottomControl.setVisibility(View.INVISIBLE); pbBottom.setVisibility(View.VISIBLE); - ImageLoader.getInstance().displayImage(thumb, ivThumb, getDefaultDisplayImageOption()); + ImageLoader.getInstance().displayImage(thumb, ivThumb, Utils.getDefaultDisplayImageOption()); CURRENT_STATE = CURRENT_STATE_NORMAL; setTitleVisibility(View.VISIBLE); if (uuid.equals(JCMediaPlayer.intance().uuid)) { @@ -156,11 +159,18 @@ public void setUp(String url, String thumb, String title, boolean ifShowTitle) { } } - public void setUpForFullscreen(String url, String thumb, String title, boolean ifFullScreen) { + /** + * 只在全全屏中调用的方法 + * + * @param url 视频地址 + * @param thumb 缩略图地址 + * @param title 标题 + */ + public void setUpForFullscreen(String url, String thumb, String title) { this.url = url; this.thumb = thumb; this.title = title; - this.ifFullScreen = ifFullScreen; + this.ifFullScreen = true; if (ifFullScreen) { ivFullScreen.setImageResource(R.drawable.shrink_video); } else { @@ -175,6 +185,11 @@ public void setUpForFullscreen(String url, String thumb, String title, boolean i setTitleVisibility(View.VISIBLE); } + /** + * 设置视频的状态 + * + * @param state int型 + */ public void setState(int state) { this.CURRENT_STATE = state; //全屏或取消全屏时继续原来的状态 @@ -218,10 +233,76 @@ public void setState(int state) { } } - public void setSeekbarOnTouchListener(OnTouchListener listener) { - mSeekbarOnTouchListener = listener; + public void onEventMainThread(VideoEvents videoEvents) { + if (videoEvents.type == VideoEvents.VE_MEDIAPLAYER_FINISH_COMPLETE) { +// if (CURRENT_STATE != CURRENT_STATE_PREPAREING) { + cancelProgressTimer(); + ivStart.setImageResource(R.drawable.click_video_play_selector); + ivThumb.setVisibility(View.VISIBLE); + ivStart.setVisibility(View.VISIBLE); +// JCMediaPlayer.intance().mediaPlayer.setDisplay(null); + //TODO 这里要将背景置黑, +// surfaceView.setBackgroundColor(R.color.black_a10_color); + CURRENT_STATE = CURRENT_STATE_NORMAL; + setKeepScreenOn(false); + sendPointEvent(ifFullScreen ? VideoEvents.POINT_AUTO_COMPLETE_FULLSCREEN : VideoEvents.POINT_AUTO_COMPLETE); + } + if (!JCMediaPlayer.intance().uuid.equals(uuid)) { + if (videoEvents.type == VideoEvents.VE_START) { + if (CURRENT_STATE != CURRENT_STATE_NORMAL) { + setState(CURRENT_STATE_NORMAL); + } + } + return; + } + if (videoEvents.type == VideoEvents.VE_PREPARED) { + if (CURRENT_STATE != CURRENT_STATE_PREPAREING) return; + JCMediaPlayer.intance().mediaPlayer.setDisplay(surfaceHolder); + JCMediaPlayer.intance().mediaPlayer.start(); + pbLoading.setVisibility(View.INVISIBLE); + ivCover.setVisibility(View.INVISIBLE); + llBottomControl.setVisibility(View.VISIBLE); + pbBottom.setVisibility(View.INVISIBLE); + CURRENT_STATE = CURRENT_STATE_PLAYING; + startDismissControlViewTimer(); + startProgressTimer(); + } else if (videoEvents.type == VideoEvents.VE_MEDIAPLAYER_UPDATE_BUFFER) { + if (CURRENT_STATE != CURRENT_STATE_NORMAL || CURRENT_STATE != CURRENT_STATE_PREPAREING) { + int percent = Integer.valueOf(videoEvents.obj.toString()); + setProgressBuffered(percent); + } + } else if (videoEvents.type == VideoEvents.VE_MEDIAPLAYER_UPDATE_PROGRESS) { + if (CURRENT_STATE != CURRENT_STATE_NORMAL || CURRENT_STATE != CURRENT_STATE_PREPAREING) { + setProgressAndTimeFromTimer(); + } + } else if (videoEvents.type == VideoEvents.VE_SURFACEHOLDER_FINISH_FULLSCREEN) { + if (isClickFullscreen) { + isFromFullScreenBackHere = true; + isClickFullscreen = false; + int prev_state = Integer.valueOf(videoEvents.obj.toString()); + setState(prev_state); + } + } else if (videoEvents.type == VideoEvents.VE_SURFACEHOLDER_CREATED) { + if (isFromFullScreenBackHere) { + JCMediaPlayer.intance().mediaPlayer.setDisplay(surfaceHolder); + stopToFullscreenOrQuitFullscreenShowDisplay(); + isFromFullScreenBackHere = false; + startDismissControlViewTimer(); + } + } else if (videoEvents.type == VideoEvents.VE_MEDIAPLAYER_RESIZE) { + int mVideoWidth = JCMediaPlayer.intance().currentVideoWidth; + int mVideoHeight = JCMediaPlayer.intance().currentVideoHeight; + if (mVideoWidth != 0 && mVideoHeight != 0) { + surfaceHolder.setFixedSize(mVideoWidth, mVideoHeight); + surfaceView.requestLayout(); + } + } else if (videoEvents.type == VideoEvents.VE_MEDIAPLAYER_SEEKCOMPLETE) { + pbLoading.setVisibility(View.INVISIBLE); + Log.i("JCVideoPlayer", "seek compile"); + } } + //*********************所有控件显示隐藏的控制********************************** private void startDismissControlViewTimer() { cancelDismissControlViewTimer(); mDismissControlViewTimer = new Timer(); @@ -242,13 +323,67 @@ public void run() { }, 2500); } + //只是onClickToggleClear这个方法中逻辑的一部分 + private void dismissControlView() { + llBottomControl.setVisibility(View.INVISIBLE); + pbBottom.setVisibility(View.VISIBLE); + setTitleVisibility(View.INVISIBLE); + ivStart.setVisibility(View.INVISIBLE); +// pbLoading.setVisibility(View.INVISIBLE); + } + private void cancelDismissControlViewTimer() { if (mDismissControlViewTimer != null) { mDismissControlViewTimer.cancel(); } } - //定时发送更新 + private void onClickToggleClear() { + if (CURRENT_STATE == CURRENT_STATE_PREPAREING) { + if (llBottomControl.getVisibility() == View.VISIBLE) { + llBottomControl.setVisibility(View.INVISIBLE); + pbBottom.setVisibility(View.VISIBLE); + setTitleVisibility(View.INVISIBLE); + } else { + llBottomControl.setVisibility(View.VISIBLE); + pbBottom.setVisibility(View.INVISIBLE); + setTitleVisibility(View.VISIBLE); + } + ivStart.setVisibility(View.INVISIBLE); + pbLoading.setVisibility(View.VISIBLE); + } else if (CURRENT_STATE == CURRENT_STATE_PLAYING) { + if (llBottomControl.getVisibility() == View.VISIBLE) { + llBottomControl.setVisibility(View.INVISIBLE); + pbBottom.setVisibility(View.VISIBLE); + setTitleVisibility(View.INVISIBLE); + ivStart.setVisibility(View.INVISIBLE); + } else { + updateStartImage(); + ivStart.setVisibility(View.VISIBLE); + llBottomControl.setVisibility(View.VISIBLE); + pbBottom.setVisibility(View.INVISIBLE); + setTitleVisibility(View.VISIBLE); + } + pbLoading.setVisibility(View.INVISIBLE); + } else if (CURRENT_STATE == CURRENT_STATE_PAUSE) { + if (llBottomControl.getVisibility() == View.VISIBLE) { + llBottomControl.setVisibility(View.INVISIBLE); + pbBottom.setVisibility(View.VISIBLE); + setTitleVisibility(View.INVISIBLE); + ivStart.setVisibility(View.INVISIBLE); + } else { + updateStartImage(); + ivStart.setVisibility(View.VISIBLE); + llBottomControl.setVisibility(View.VISIBLE); + pbBottom.setVisibility(View.INVISIBLE); + setTitleVisibility(View.VISIBLE); + } + pbLoading.setVisibility(View.INVISIBLE); + } + } + //******************************************************* + + //***************************加载进度的控制**************************** private void startProgressTimer() { cancelProgressTimer(); mUpdateProgressTimer = new Timer(); @@ -277,15 +412,9 @@ private void cancelProgressTimer() { } } } + //******************************************************* - private void dismissControlView() { - llBottomControl.setVisibility(View.INVISIBLE); - pbBottom.setVisibility(View.VISIBLE); - setTitleVisibility(View.INVISIBLE); - ivStart.setVisibility(View.INVISIBLE); -// pbLoading.setVisibility(View.INVISIBLE); - } - + //**************************是否显示标题的控制***************************** public void setIfShowTitle(boolean ifShowTitle) { this.ifShowTitle = ifShowTitle; } @@ -301,6 +430,7 @@ private void setTitleVisibility(int visable) { } } } + //******************************************************* /** * 目前认为详细的判断和重复的设置是有相当必要的,也可以包装成方法 @@ -369,7 +499,7 @@ public void onClick(View v) { } clickfullscreentime = System.currentTimeMillis(); } else if (i == R.id.surfaceView || i == R.id.parentview) { - toggleClear(); + onClickToggleClear(); startDismissControlViewTimer(); sendPointEvent(ifFullScreen ? VideoEvents.POINT_CLICK_BLANK_FULLSCREEN : VideoEvents.POINT_CLICK_BLANK); } else if (i == R.id.bottom_control) { @@ -379,61 +509,6 @@ public void onClick(View v) { } } - private void toggleClear() { - if (CURRENT_STATE == CURRENT_STATE_PREPAREING) { - if (llBottomControl.getVisibility() == View.VISIBLE) { - llBottomControl.setVisibility(View.INVISIBLE); - pbBottom.setVisibility(View.VISIBLE); - setTitleVisibility(View.INVISIBLE); - } else { - llBottomControl.setVisibility(View.VISIBLE); - pbBottom.setVisibility(View.INVISIBLE); - setTitleVisibility(View.VISIBLE); - } - ivStart.setVisibility(View.INVISIBLE); - pbLoading.setVisibility(View.VISIBLE); - } else if (CURRENT_STATE == CURRENT_STATE_PLAYING) { - if (llBottomControl.getVisibility() == View.VISIBLE) { - llBottomControl.setVisibility(View.INVISIBLE); - pbBottom.setVisibility(View.VISIBLE); - setTitleVisibility(View.INVISIBLE); - ivStart.setVisibility(View.INVISIBLE); - } else { - updateStartImage(); - ivStart.setVisibility(View.VISIBLE); - llBottomControl.setVisibility(View.VISIBLE); - pbBottom.setVisibility(View.INVISIBLE); - setTitleVisibility(View.VISIBLE); - } - pbLoading.setVisibility(View.INVISIBLE); - } else if (CURRENT_STATE == CURRENT_STATE_PAUSE) { - if (llBottomControl.getVisibility() == View.VISIBLE) { - llBottomControl.setVisibility(View.INVISIBLE); - pbBottom.setVisibility(View.VISIBLE); - setTitleVisibility(View.INVISIBLE); - ivStart.setVisibility(View.INVISIBLE); - } else { - updateStartImage(); - ivStart.setVisibility(View.VISIBLE); - llBottomControl.setVisibility(View.VISIBLE); - pbBottom.setVisibility(View.INVISIBLE); - setTitleVisibility(View.VISIBLE); - } - pbLoading.setVisibility(View.INVISIBLE); - } - } - - public void quitFullScreen() { - FullScreenActivity.manualQuit = true; - clickfullscreentime = System.currentTimeMillis(); - JCMediaPlayer.intance().mediaPlayer.pause(); - JCMediaPlayer.intance().mediaPlayer.setDisplay(null); - JCMediaPlayer.intance().revertUuid(); - VideoEvents videoEvents = new VideoEvents().setType(VideoEvents.VE_SURFACEHOLDER_FINISH_FULLSCREEN); - videoEvents.obj = CURRENT_STATE; - EventBus.getDefault().post(videoEvents); - sendPointEvent(VideoEvents.POINT_QUIT_FULLSCREEN); - } private void updateStartImage() { if (CURRENT_STATE == CURRENT_STATE_PLAYING) { @@ -443,6 +518,7 @@ private void updateStartImage() { } } + //************************进度条的控制******************************* private void setProgressBuffered(int secProgress) { if (secProgress >= 0) { sbProgress.setSecondaryProgress(secProgress); @@ -450,7 +526,6 @@ private void setProgressBuffered(int secProgress) { } } - //设置进度条和进度时间 private void setProgressAndTimeFromTimer() { int position = JCMediaPlayer.intance().mediaPlayer.getCurrentPosition(); int duration = JCMediaPlayer.intance().mediaPlayer.getDuration(); @@ -463,81 +538,10 @@ private void setProgressAndTime(int progress, int currentTime, int totalTime) { sbProgress.setProgress(progress); pbBottom.setProgress(progress); } - tvTimeCurrent.setText(stringForTime(currentTime)); - tvTimeTotal.setText(stringForTime(totalTime)); - } - - public void onEventMainThread(VideoEvents videoEvents) { - if (videoEvents.type == VideoEvents.VE_MEDIAPLAYER_FINISH_COMPLETE) { -// if (CURRENT_STATE != CURRENT_STATE_PREPAREING) { - cancelProgressTimer(); - ivStart.setImageResource(R.drawable.click_video_play_selector); - ivThumb.setVisibility(View.VISIBLE); - ivStart.setVisibility(View.VISIBLE); -// JCMediaPlayer.intance().mediaPlayer.setDisplay(null); - //TODO 这里要将背景置黑, -// surfaceView.setBackgroundColor(R.color.black_a10_color); - CURRENT_STATE = CURRENT_STATE_NORMAL; - setKeepScreenOn(false); - sendPointEvent(ifFullScreen ? VideoEvents.POINT_AUTO_COMPLETE_FULLSCREEN : VideoEvents.POINT_AUTO_COMPLETE); - } - if (!JCMediaPlayer.intance().uuid.equals(uuid)) { - if (videoEvents.type == VideoEvents.VE_START) { - if (CURRENT_STATE != CURRENT_STATE_NORMAL) { - setState(CURRENT_STATE_NORMAL); - } - } - return; - } - if (videoEvents.type == VideoEvents.VE_PREPARED) { - if (CURRENT_STATE != CURRENT_STATE_PREPAREING) return; - JCMediaPlayer.intance().mediaPlayer.setDisplay(surfaceHolder); - JCMediaPlayer.intance().mediaPlayer.start(); - pbLoading.setVisibility(View.INVISIBLE); - ivCover.setVisibility(View.INVISIBLE); - llBottomControl.setVisibility(View.VISIBLE); - pbBottom.setVisibility(View.INVISIBLE); - CURRENT_STATE = CURRENT_STATE_PLAYING; - startDismissControlViewTimer(); - startProgressTimer(); - } else if (videoEvents.type == VideoEvents.VE_MEDIAPLAYER_UPDATE_BUFFER) { - if (CURRENT_STATE != CURRENT_STATE_NORMAL || CURRENT_STATE != CURRENT_STATE_PREPAREING) { - int percent = Integer.valueOf(videoEvents.obj.toString()); - setProgressBuffered(percent); - } - } else if (videoEvents.type == VideoEvents.VE_MEDIAPLAYER_UPDATE_PROGRESS) { - if (CURRENT_STATE != CURRENT_STATE_NORMAL || CURRENT_STATE != CURRENT_STATE_PREPAREING) { - setProgressAndTimeFromTimer(); - } - } else if (videoEvents.type == VideoEvents.VE_SURFACEHOLDER_FINISH_FULLSCREEN) { - if (isClickFullscreen) { - isFromFullScreenBackHere = true; - isClickFullscreen = false; - int prev_state = Integer.valueOf(videoEvents.obj.toString()); - setState(prev_state); - } - } else if (videoEvents.type == VideoEvents.VE_SURFACEHOLDER_CREATED) { - if (isFromFullScreenBackHere) { - JCMediaPlayer.intance().mediaPlayer.setDisplay(surfaceHolder); - stopToFullscreenOrQuitFullscreenShowDisplay(); - isFromFullScreenBackHere = false; - startDismissControlViewTimer(); - } - } else if (videoEvents.type == VideoEvents.VE_MEDIAPLAYER_RESIZE) { - int mVideoWidth = JCMediaPlayer.intance().currentVideoWidth; - int mVideoHeight = JCMediaPlayer.intance().currentVideoHeight; - if (mVideoWidth != 0 && mVideoHeight != 0) { - surfaceHolder.setFixedSize(mVideoWidth, mVideoHeight); - surfaceView.requestLayout(); - } - } else if (videoEvents.type == VideoEvents.VE_MEDIAPLAYER_SEEKCOMPLETE) { - pbLoading.setVisibility(View.INVISIBLE); - Log.i("JCVideoPlayer", "seek compile"); - } + tvTimeCurrent.setText(Utils.stringForTime(currentTime)); + tvTimeTotal.setText(Utils.stringForTime(totalTime)); } - - boolean isFromFullScreenBackHere = false;//如果是true表示这个正在不是全屏,并且全屏刚推出,总之进入过全屏 - boolean isClickFullscreen = false; + //******************************************************* public void release() { if ((System.currentTimeMillis() - clickfullscreentime) < FULL_SCREEN_NORMAL_DELAY) return; @@ -584,18 +588,17 @@ protected void onAttachedToWindow() { } } - @Override - public void surfaceCreated(SurfaceHolder holder) { - //TODO MediaPlayer set holder,MediaPlayer prepareToPlay - EventBus.getDefault().post(new VideoEvents().setType(VideoEvents.VE_SURFACEHOLDER_CREATED)); - if (ifFullScreen) { - JCMediaPlayer.intance().mediaPlayer.setDisplay(surfaceHolder); - stopToFullscreenOrQuitFullscreenShowDisplay(); - } - if (CURRENT_STATE != CURRENT_STATE_NORMAL) { - startDismissControlViewTimer(); - } - + //************************全屏的控制******************************* + public void quitFullScreen() { + FullScreenActivity.manualQuit = true; + clickfullscreentime = System.currentTimeMillis(); + JCMediaPlayer.intance().mediaPlayer.pause(); + JCMediaPlayer.intance().mediaPlayer.setDisplay(null); + JCMediaPlayer.intance().revertUuid(); + VideoEvents videoEvents = new VideoEvents().setType(VideoEvents.VE_SURFACEHOLDER_FINISH_FULLSCREEN); + videoEvents.obj = CURRENT_STATE; + EventBus.getDefault().post(videoEvents); + sendPointEvent(VideoEvents.POINT_QUIT_FULLSCREEN); } private void stopToFullscreenOrQuitFullscreenShowDisplay() { @@ -619,32 +622,30 @@ public void run() { JCMediaPlayer.intance().mediaPlayer.start(); } } + //******************************************************* @Override - public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { + public void surfaceCreated(SurfaceHolder holder) { + //TODO MediaPlayer set holder,MediaPlayer prepareToPlay + EventBus.getDefault().post(new VideoEvents().setType(VideoEvents.VE_SURFACEHOLDER_CREATED)); + if (ifFullScreen) { + JCMediaPlayer.intance().mediaPlayer.setDisplay(surfaceHolder); + stopToFullscreenOrQuitFullscreenShowDisplay(); + } + if (CURRENT_STATE != CURRENT_STATE_NORMAL) { + startDismissControlViewTimer(); + } } @Override - public void surfaceDestroyed(SurfaceHolder holder) { + public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { } - private 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 mFormatBuilder = new StringBuilder(); - Formatter mFormatter = new Formatter(mFormatBuilder, Locale.getDefault()); - if (hours > 0) { - return mFormatter.format("%d:%02d:%02d", hours, minutes, seconds).toString(); - } else { - return mFormatter.format("%02d:%02d", minutes, seconds).toString(); - } + @Override + public void surfaceDestroyed(SurfaceHolder holder) { + } /** @@ -657,23 +658,10 @@ public static void releaseAllVideo() { EventBus.getDefault().post(new VideoEvents().setType(VideoEvents.VE_MEDIAPLAYER_FINISH_COMPLETE)); } - public DisplayImageOptions getDefaultDisplayImageOption() { - DisplayImageOptions options = new DisplayImageOptions.Builder() - .showImageOnLoading(new ColorDrawable(Color.parseColor("#f0f0f0"))) - .resetViewBeforeLoading(true) - .cacheInMemory(true) - .cacheOnDisk(true) - .considerExifParams(true) - .imageScaleType(ImageScaleType.EXACTLY_STRETCHED) - .bitmapConfig(Bitmap.Config.RGB_565) - .displayer(new FadeInBitmapDisplayer(500)) // 设置图片渐显的时间 -// .delayBeforeLoading(300) // 下载前的延迟时间 - .build(); - return options; - } - /** * 有特殊需要的客户端 + * + * @param onClickListener 开始按钮点击的回调函数 */ @Deprecated public void setStartListener(OnClickListener onClickListener) { @@ -693,7 +681,9 @@ private void sendPointEvent(int type) { EventBus.getDefault().post(videoEvents); } - private boolean touchingProgressBar = false; + public void setSeekbarOnTouchListener(OnTouchListener listener) { + mSeekbarOnTouchListener = listener; + } @Override public boolean onTouch(View v, MotionEvent event) { @@ -708,8 +698,6 @@ public boolean onTouch(View v, MotionEvent event) { startDismissControlViewTimer(); startProgressTimer(); sendPointEvent(ifFullScreen ? VideoEvents.POINT_CLICK_SEEKBAR_FULLSCREEN : VideoEvents.POINT_CLICK_SEEKBAR); - - break; } diff --git a/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/Utils.java b/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/Utils.java new file mode 100644 index 000000000..f4c4901f4 --- /dev/null +++ b/jcvideoplayer-lib/src/main/java/fm/jiecao/jcvideoplayer_lib/Utils.java @@ -0,0 +1,52 @@ +package fm.jiecao.jcvideoplayer_lib; + +import android.graphics.Bitmap; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; + +import com.nostra13.universalimageloader.core.DisplayImageOptions; +import com.nostra13.universalimageloader.core.assist.ImageScaleType; +import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer; + +import java.util.Formatter; +import java.util.Locale; + +/** + * 最俗的类名 + * Created by Nathen + * On 2016/02/21 12:25 + */ +public class Utils { + public static DisplayImageOptions getDefaultDisplayImageOption() { + DisplayImageOptions options = new DisplayImageOptions.Builder() + .showImageOnLoading(new ColorDrawable(Color.parseColor("#f0f0f0"))) + .resetViewBeforeLoading(true) + .cacheInMemory(true) + .cacheOnDisk(true) + .considerExifParams(true) + .imageScaleType(ImageScaleType.EXACTLY_STRETCHED) + .bitmapConfig(Bitmap.Config.RGB_565) + .displayer(new FadeInBitmapDisplayer(500)) // 设置图片渐显的时间 +// .delayBeforeLoading(300) // 下载前的延迟时间 + .build(); + return options; + } + + 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 mFormatBuilder = new StringBuilder(); + Formatter mFormatter = new Formatter(mFormatBuilder, Locale.getDefault()); + if (hours > 0) { + return mFormatter.format("%d:%02d:%02d", hours, minutes, seconds).toString(); + } else { + return mFormatter.format("%02d:%02d", minutes, seconds).toString(); + } + } + +} diff --git a/jcvideoplayer-lib/src/main/res/drawable/seek_thumb_normal.xml b/jcvideoplayer-lib/src/main/res/drawable/seek_thumb_normal.xml index 32be9e36d..347dd3814 100644 --- a/jcvideoplayer-lib/src/main/res/drawable/seek_thumb_normal.xml +++ b/jcvideoplayer-lib/src/main/res/drawable/seek_thumb_normal.xml @@ -1,6 +1,5 @@ - - - + diff --git a/jcvideoplayer-lib/src/main/res/layout/video_control_view.xml b/jcvideoplayer-lib/src/main/res/layout/video_control_view.xml index 635b4583b..f0cbc511e 100644 --- a/jcvideoplayer-lib/src/main/res/layout/video_control_view.xml +++ b/jcvideoplayer-lib/src/main/res/layout/video_control_view.xml @@ -13,8 +13,7 @@ android:id="@+id/surfaceView" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout_centerInParent="true" - /> + android:layout_centerInParent="true" />