Skip to content

Commit

Permalink
1.添加清楚视频缓存的方法
Browse files Browse the repository at this point in the history
2.重命名各个类
  • Loading branch information
Doikki committed May 19, 2017
1 parent 2549a16 commit a1f8b39
Show file tree
Hide file tree
Showing 20 changed files with 308 additions and 144 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Step 1.Add it in your root build.gradle at the end of repositories:
Step 2. Add the dependency

dependencies {
compile 'com.github.DevlinChiu:MagicPlayer:1.0.1'
compile 'com.github.DevlinChiu:MagicPlayer:1.0.2'
}
### ProGuard

Expand Down
28 changes: 14 additions & 14 deletions app/src/main/java/com/devlin_n/magicplayer/FullScreenActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.devlin_n.magic_player.player.IjkVideoView;
import com.devlin_n.magic_player.player.MagicVideoView;

import static com.devlin_n.magic_player.player.IjkVideoView.ALERT_WINDOW_PERMISSION_CODE;
import static com.devlin_n.magic_player.player.MagicVideoView.ALERT_WINDOW_PERMISSION_CODE;

/**
* 全屏播放
Expand All @@ -20,46 +20,46 @@

public class FullScreenActivity extends AppCompatActivity{

private IjkVideoView ijkVideoView;
private MagicVideoView magicVideoView;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ijkVideoView = new IjkVideoView(this);
setContentView(ijkVideoView);
ijkVideoView
magicVideoView = new MagicVideoView(this);
setContentView(magicVideoView);
magicVideoView
.init()
.autoRotate()
.alwaysFullScreen()
.setTitle("这是一个标题")
.setUrl("http://flv2.bn.netease.com/videolib3/1611/28/GbgsL3639/HD/movie_index.m3u8")
.setMediaController(IjkVideoView.VOD)
.setScreenType(IjkVideoView.SCREEN_TYPE_4_3)
.setVideoController(MagicVideoView.VOD)
.setScreenType(MagicVideoView.SCREEN_TYPE_4_3)
.start();
}

@Override
protected void onPause() {
super.onPause();
ijkVideoView.pause();
magicVideoView.pause();
}

@Override
protected void onResume() {
super.onResume();
ijkVideoView.resume();
ijkVideoView.stopFloatWindow();
magicVideoView.resume();
magicVideoView.stopFloatWindow();
}

@Override
protected void onDestroy() {
super.onDestroy();
ijkVideoView.release();
magicVideoView.release();
}

@Override
public void onBackPressed() {
if (!ijkVideoView.onBackPressed()){
if (!magicVideoView.onBackPressed()){
super.onBackPressed();
}
}
Expand All @@ -74,7 +74,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (!Settings.canDrawOverlays(this)) {
Toast.makeText(FullScreenActivity.this, "权限授予失败,无法开启悬浮窗", Toast.LENGTH_SHORT).show();
} else {
ijkVideoView.startFloatWindow();
magicVideoView.startFloatWindow();
}
}
}
Expand Down
36 changes: 18 additions & 18 deletions app/src/main/java/com/devlin_n/magicplayer/LivePlayerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import android.view.View;
import android.widget.Toast;

import com.devlin_n.magic_player.player.IjkVideoView;
import com.devlin_n.magic_player.player.MagicVideoView;

import static android.os.Build.VERSION_CODES.M;
import static com.devlin_n.magic_player.player.IjkVideoView.ALERT_WINDOW_PERMISSION_CODE;
import static com.devlin_n.magic_player.player.MagicVideoView.ALERT_WINDOW_PERMISSION_CODE;

/**
* 直播播放
Expand All @@ -23,7 +23,7 @@

public class LivePlayerActivity extends AppCompatActivity {

private IjkVideoView ijkVideoView;
private MagicVideoView magicVideoView;
private static final String URL = "http://ivi.bupt.edu.cn/hls/cctv6.m3u8";

@Override
Expand All @@ -35,16 +35,16 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
actionBar.setTitle("LIVE");
actionBar.setDisplayHomeAsUpEnabled(true);
}
ijkVideoView = (IjkVideoView) findViewById(R.id.ijk_video_view);
magicVideoView = (MagicVideoView) findViewById(R.id.magic_video_view);
// int widthPixels = getResources().getDisplayMetrics().widthPixels;
// ijkVideoView.setLayoutParams(new LinearLayout.LayoutParams(widthPixels, widthPixels / 4 * 3));
// magicVideoView.setLayoutParams(new LinearLayout.LayoutParams(widthPixels, widthPixels / 4 * 3));

ijkVideoView
magicVideoView
.init()
.autoRotate()
.setUrl(URL)
.setTitle("CCTV6")
.setMediaController(IjkVideoView.LIVE)
.setVideoController(MagicVideoView.LIVE)
.start();
}

Expand All @@ -59,26 +59,26 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
protected void onPause() {
super.onPause();
ijkVideoView.pause();
magicVideoView.pause();
}

@Override
protected void onResume() {
super.onResume();
ijkVideoView.resume();
ijkVideoView.stopFloatWindow();
magicVideoView.resume();
magicVideoView.stopFloatWindow();
}

@Override
protected void onDestroy() {
super.onDestroy();
ijkVideoView.release();
magicVideoView.release();
}


@Override
public void onBackPressed() {
if (!ijkVideoView.onBackPressed()) {
if (!magicVideoView.onBackPressed()) {
super.onBackPressed();
}
}
Expand All @@ -93,28 +93,28 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (!Settings.canDrawOverlays(this)) {
Toast.makeText(LivePlayerActivity.this, "权限授予失败,无法开启悬浮窗", Toast.LENGTH_SHORT).show();
} else {
ijkVideoView.startFloatWindow();
magicVideoView.startFloatWindow();
}
}
}

public void startFloatWindow(View view) {
ijkVideoView.startFloatWindow();
magicVideoView.startFloatWindow();
}

public void wide(View view) {
ijkVideoView.setScreenType(IjkVideoView.SCREEN_TYPE_16_9);
magicVideoView.setScreenType(MagicVideoView.SCREEN_TYPE_16_9);
}

public void tv(View view) {
ijkVideoView.setScreenType(IjkVideoView.SCREEN_TYPE_4_3);
magicVideoView.setScreenType(MagicVideoView.SCREEN_TYPE_4_3);
}

public void match(View view) {
ijkVideoView.setScreenType(IjkVideoView.SCREEN_TYPE_MATCH_PARENT);
magicVideoView.setScreenType(MagicVideoView.SCREEN_TYPE_MATCH_PARENT);
}

public void original(View view) {
ijkVideoView.setScreenType(IjkVideoView.SCREEN_TYPE_ORIGINAL);
magicVideoView.setScreenType(MagicVideoView.SCREEN_TYPE_ORIGINAL);
}
}
5 changes: 5 additions & 0 deletions app/src/main/java/com/devlin_n/magicplayer/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.view.View;

import com.devlin_n.magic_player.player.BackgroundPlayService;
import com.devlin_n.magic_player.player.VideoCacheManager;

public class MainActivity extends AppCompatActivity {

Expand All @@ -31,4 +32,8 @@ public void closeFloatWindow(View view) {
public void startFullScreen(View view) {
startActivity(new Intent(this, FullScreenActivity.class));
}

public void clearCache(View view) {
VideoCacheManager.clearAllCache(this);
}
}
36 changes: 18 additions & 18 deletions app/src/main/java/com/devlin_n/magicplayer/VodPlayerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import android.view.View;
import android.widget.Toast;

import com.devlin_n.magic_player.player.IjkVideoView;
import com.devlin_n.magic_player.player.MagicVideoView;

import static com.devlin_n.magic_player.player.IjkVideoView.ALERT_WINDOW_PERMISSION_CODE;
import static com.devlin_n.magic_player.player.MagicVideoView.ALERT_WINDOW_PERMISSION_CODE;

/**
* 点播播放
Expand All @@ -23,7 +23,7 @@

public class VodPlayerActivity extends AppCompatActivity {

private IjkVideoView ijkVideoView;
private MagicVideoView magicVideoView;
private static final String URL_VOD = "http://mov.bn.netease.com/open-movie/nos/flv/2017/01/03/SC8U8K7BC_hd.flv";
private static final String URL_AD = "http://gslb.miaopai.com/stream/FQXM04zrW1dcXGiPdJ6Q3KAq2Fpv4TLV.mp4";

Expand All @@ -36,22 +36,22 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
actionBar.setTitle("VOD");
actionBar.setDisplayHomeAsUpEnabled(true);
}
ijkVideoView = (IjkVideoView) findViewById(R.id.ijk_video_view);
magicVideoView = (MagicVideoView) findViewById(R.id.magic_video_view);
// int widthPixels = getResources().getDisplayMetrics().widthPixels;
// ijkVideoView.setLayoutParams(new LinearLayout.LayoutParams(widthPixels, widthPixels / 16 * 9));
// magicVideoView.setLayoutParams(new LinearLayout.LayoutParams(widthPixels, widthPixels / 16 * 9));

// List<VideoModel> videos = new ArrayList<>();
// videos.add(new VideoModel(URL_AD, "广告", IjkVideoView.AD));
// videos.add(new VideoModel(URL_VOD, "网易公开课-如何掌控你的自由时间", IjkVideoView.VOD));

ijkVideoView
magicVideoView
.init()
.autoRotate()
.enableCache()
// .setVideos(videos)
.setUrl(URL_VOD)
.setTitle("网易公开课-如何掌控你的自由时间")
.setMediaController(IjkVideoView.VOD)
.setVideoController(MagicVideoView.VOD)
.start();
}

Expand All @@ -66,26 +66,26 @@ public boolean onOptionsItemSelected(MenuItem item) {
@Override
protected void onPause() {
super.onPause();
ijkVideoView.pause();
magicVideoView.pause();
}

@Override
protected void onResume() {
super.onResume();
ijkVideoView.resume();
ijkVideoView.stopFloatWindow();
magicVideoView.resume();
magicVideoView.stopFloatWindow();
}

@Override
protected void onDestroy() {
super.onDestroy();
ijkVideoView.release();
magicVideoView.release();
}


@Override
public void onBackPressed() {
if (!ijkVideoView.onBackPressed()) {
if (!magicVideoView.onBackPressed()) {
super.onBackPressed();
}
}
Expand All @@ -100,28 +100,28 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (!Settings.canDrawOverlays(this)) {
Toast.makeText(VodPlayerActivity.this, "权限授予失败,无法开启悬浮窗", Toast.LENGTH_SHORT).show();
} else {
ijkVideoView.startFloatWindow();
magicVideoView.startFloatWindow();
}
}
}

public void startFloatWindow(View view) {
ijkVideoView.startFloatWindow();
magicVideoView.startFloatWindow();
}

public void wide(View view) {
ijkVideoView.setScreenType(IjkVideoView.SCREEN_TYPE_16_9);
magicVideoView.setScreenType(MagicVideoView.SCREEN_TYPE_16_9);
}

public void tv(View view) {
ijkVideoView.setScreenType(IjkVideoView.SCREEN_TYPE_4_3);
magicVideoView.setScreenType(MagicVideoView.SCREEN_TYPE_4_3);
}

public void match(View view) {
ijkVideoView.setScreenType(IjkVideoView.SCREEN_TYPE_MATCH_PARENT);
magicVideoView.setScreenType(MagicVideoView.SCREEN_TYPE_MATCH_PARENT);
}

public void original(View view) {
ijkVideoView.setScreenType(IjkVideoView.SCREEN_TYPE_ORIGINAL);
magicVideoView.setScreenType(MagicVideoView.SCREEN_TYPE_ORIGINAL);
}
}
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_live_player.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
android:layout_height="match_parent"
android:orientation="vertical">

<com.devlin_n.magic_player.player.IjkVideoView
android:id="@+id/ijk_video_view"
<com.devlin_n.magic_player.player.MagicVideoView
android:id="@+id/magic_video_view"
android:layout_width="match_parent"
android:layout_height="300dp" />

Expand Down
30 changes: 20 additions & 10 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="VOD PLAYER"
android:onClick="skipToVodPlayer"/>
android:onClick="skipToVodPlayer"
android:text="VOD PLAYER" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="LIVE PLAYER"
android:onClick="skipToLivePlayer"/>
android:onClick="skipToLivePlayer"
android:text="LIVE PLAYER" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ALWAYS ON FULLSCREEN"
android:onClick="startFullScreen"/>
android:onClick="startFullScreen"
android:text="ALWAYS ON FULLSCREEN" />

<Button
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="closeFloatWindow"
android:text="CLOSE PIP"/>
android:text="CLOSE PIP" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="clearCache"
android:text="CLEAR CACHE" />

</LinearLayout>
Loading

0 comments on commit a1f8b39

Please sign in to comment.