最近項目中有須要用在線視頻播放。以前有關於視頻播放介紹了一些工具使用。如ijkplayer ,ExoPlayer,Vitamio,android-UniversalMusicPlayer.java
想要了解更多請參考Androidstarjack的博客地址:android
今天打算介紹一個新的音視頻播放器 :JieCaoVideoPlayer
也是項目中將要用到的。要求能在線進行播放。或者是播放本地視頻github
先看一下效果圖吧:web
一行代碼快速實現視頻播放,Android視頻播放,AndroidMP3播放,安卓視頻播放一行代碼搞定,真正實現Android的全屏功能,立志成爲Android平臺使用最普遍的視頻播放控件api
導入到項目(建議使用第三方庫導入的形式)bash
compile 'fm.jiecao:jiecaovideoplayer:5.5.2'複製代碼
<fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard
android:id="@+id/videoplayer"
android:layout_width="match_parent"
android:layout_height="200dp"/>複製代碼
在java代碼中初始化JCVideoPlayer組件ID,並配置相對應的URL微信
或者設置視頻地址、縮略圖地址、標題ide
JCVideoPlayerStandard jcVideoPlayerStandard = (JCVideoPlayerStandard) findViewById(R.id.videoplayer);
jcVideoPlayerStandard.setUp("http://2449.vod.myqcloud.com/2449_22ca37a6ea9011e5acaaf51d105342e3.f20.mp4", JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL, "嫂子閉眼睛");
jcVideoPlayerStandard.thumbImageView.setImage("http://p.qpic.cn/videoyun/0/2449_43b6f696980311e59ed467f22794e792_1/640");複製代碼
@Override
public void onBackPressed() {
if (JCVideoPlayer.backPress()) {
return;
}
super.onBackPressed();
}
@Override
protected void onPause() {
super.onPause();
JCVideoPlayer.releaseAllVideos();
}複製代碼
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:screenOrientation="portrait" /> <!-- or android:screenOrientation="landscape"-->複製代碼
全屏時啓動新Activity實現播放器真正的全屏功能工具
能在ListView、ViewPager和ListView、ViewPager和Fragment等多重嵌套模式下全屏工做
ListView的拖拽和ViewPager的滑動時若是劃出屏幕會自動重置視頻
視頻大小的屏幕適配,寬或長至少有兩個對邊是充滿屏幕的,另外兩個方向居中
能夠在加載、暫停、播放等各類狀態中正常進入全屏和退出全屏
根據本身應用的顏色風格換膚
送上一個播放地址:
flashmedia.eastday.com/newdate/new…
[wdl.wallstreetcn.com/41aae4d2-39…)
音樂地址:
o6wf52jln.bkt.clouddn.com/演員.mp3
相關代碼:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
JCVideoPlayerStandard mJcVideoPlayerStandard;
Button mTinyWindow, mAutoTinyWindow, mAboutListView, mPlayDirectly, mAboutApi, mAboutWebView,play_music;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTinyWindow = (Button) findViewById(R.id.tiny_window);
mAutoTinyWindow = (Button) findViewById(R.id.auto_tiny_window);
mPlayDirectly = (Button) findViewById(R.id.play_directly_without_layout);
mAboutListView = (Button) findViewById(R.id.about_listview);
mAboutApi = (Button) findViewById(R.id.about_api);
play_music = (Button) findViewById(R.id.play_music);
mAboutWebView = (Button) findViewById(R.id.about_webview);
mTinyWindow.setOnClickListener(this);
mAutoTinyWindow.setOnClickListener(this);
mAboutListView.setOnClickListener(this);
mPlayDirectly.setOnClickListener(this);
mAboutApi.setOnClickListener(this);
mAboutWebView.setOnClickListener(this);
play_music.setOnClickListener(this);
mJcVideoPlayerStandard = (JCVideoPlayerStandard) findViewById(R.id.jc_video);
mJcVideoPlayerStandard.setUp("http://www.jmzsjy.com/UploadFile/微課/地方風味小吃——宮廷香酥牛肉餅.mp4"
, JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL, "視頻播放");
Picasso.with(this)
.load("http://img4.jiecaojingxuan.com/2016/11/23/00b026e7-b830-4994-bc87-38f4033806a6.jpg@!640_360")
.into(mJcVideoPlayerStandard.thumbImageView);
JCVideoPlayer.setJcUserAction(new MyUserActionStandard());
}
@Override
protected void onPause() {
super.onPause();
JCVideoPlayer.releaseAllVideos();
}
@Override
public void onBackPressed() {
if (JCVideoPlayer.backPress()) {
return;
}
super.onBackPressed();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.tiny_window:
mJcVideoPlayerStandard.startWindowTiny();
break;
case R.id.auto_tiny_window:
startActivity(new Intent(MainActivity.this, AutoTinyActivity.class));
break;
case R.id.play_directly_without_layout:
startActivity(new Intent(MainActivity.this, PlayDirectlyActivity.class));
break;
case R.id.about_listview:
startActivity(new Intent(MainActivity.this, ListViewActivity.class));
break;
case R.id.about_api:
startActivity(new Intent(MainActivity.this, ApiActivity.class));
break;
case R.id.about_webview:
startActivity(new Intent(MainActivity.this, WebViewActivity.class));
break;
case R.id.play_music:
startActivity(new Intent(MainActivity.this, PlayMusicActivity.class));
break;
}
}
class MyUserActionStandard implements JCUserActionStandard {
@Override
public void onEvent(int type, String url, int screen, Object... objects) {
switch (type) {
case JCUserAction.ON_CLICK_START_ICON:
Log.i("USER_EVENT", "ON_CLICK_START_ICON" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
break;
case JCUserAction.ON_CLICK_START_ERROR:
Log.i("USER_EVENT", "ON_CLICK_START_ERROR" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
break;
case JCUserAction.ON_CLICK_START_AUTO_COMPLETE:
Log.i("USER_EVENT", "ON_CLICK_START_AUTO_COMPLETE" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
break;
case JCUserAction.ON_CLICK_PAUSE:
Log.i("USER_EVENT", "ON_CLICK_PAUSE" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
break;
case JCUserAction.ON_CLICK_RESUME:
Log.i("USER_EVENT", "ON_CLICK_RESUME" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
break;
case JCUserAction.ON_SEEK_POSITION:
Log.i("USER_EVENT", "ON_SEEK_POSITION" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
break;
case JCUserAction.ON_AUTO_COMPLETE:
Log.i("USER_EVENT", "ON_AUTO_COMPLETE" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
break;
case JCUserAction.ON_ENTER_FULLSCREEN:
Log.i("USER_EVENT", "ON_ENTER_FULLSCREEN" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
break;
case JCUserAction.ON_QUIT_FULLSCREEN:
Log.i("USER_EVENT", "ON_QUIT_FULLSCREEN" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
break;
case JCUserAction.ON_ENTER_TINYSCREEN:
Log.i("USER_EVENT", "ON_ENTER_TINYSCREEN" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
break;
case JCUserAction.ON_QUIT_TINYSCREEN:
Log.i("USER_EVENT", "ON_QUIT_TINYSCREEN" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
break;
case JCUserAction.ON_TOUCH_SCREEN_SEEK_VOLUME:
Log.i("USER_EVENT", "ON_TOUCH_SCREEN_SEEK_VOLUME" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
break;
case JCUserAction.ON_TOUCH_SCREEN_SEEK_POSITION:
Log.i("USER_EVENT", "ON_TOUCH_SCREEN_SEEK_POSITION" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
break;
case JCUserActionStandard.ON_CLICK_START_THUMB:
Log.i("USER_EVENT", "ON_CLICK_START_THUMB" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
break;
case JCUserActionStandard.ON_CLICK_BLANK:
Log.i("USER_EVENT", "ON_CLICK_BLANK" + " title is : " + (objects.length == 0 ? "" : objects[0]) + " url is : " + url + " screen is : " + screen);
break;
default:
Log.i("USER_EVENT", "unknow");
break;
}
}
}
}複製代碼
相關佈局 activity_main.xml:
<?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:orientation="vertical">
<fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard
android:id="@+id/jc_video"
android:layout_width="300dp"
android:layout_height="300dp" />
</LinearLayout>複製代碼
資源下載:
GitHub連接下載:複製代碼
CSDN連接下載:複製代碼
download.csdn.net/download/an…
想要了解更多請參考Androidstarjack的博客地址:
若是你以爲此文對您有所幫助,歡迎入羣 QQ交流羣 :232203809
微信公衆號:終端研發部
(歡迎關注學習和交流)