diff --git a/README.md b/README.md index ba126309..63e91659 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/app/src/main/java/com/devlin_n/magicplayer/FullScreenActivity.java b/app/src/main/java/com/devlin_n/magicplayer/FullScreenActivity.java index 01ef153e..85586db4 100644 --- a/app/src/main/java/com/devlin_n/magicplayer/FullScreenActivity.java +++ b/app/src/main/java/com/devlin_n/magicplayer/FullScreenActivity.java @@ -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; /** * 全屏播放 @@ -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(); } } @@ -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(); } } } diff --git a/app/src/main/java/com/devlin_n/magicplayer/LivePlayerActivity.java b/app/src/main/java/com/devlin_n/magicplayer/LivePlayerActivity.java index 1c790c36..d88e3fe1 100644 --- a/app/src/main/java/com/devlin_n/magicplayer/LivePlayerActivity.java +++ b/app/src/main/java/com/devlin_n/magicplayer/LivePlayerActivity.java @@ -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; /** * 直播播放 @@ -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 @@ -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(); } @@ -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(); } } @@ -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); } } diff --git a/app/src/main/java/com/devlin_n/magicplayer/MainActivity.java b/app/src/main/java/com/devlin_n/magicplayer/MainActivity.java index 9ddeec02..9272d2e7 100644 --- a/app/src/main/java/com/devlin_n/magicplayer/MainActivity.java +++ b/app/src/main/java/com/devlin_n/magicplayer/MainActivity.java @@ -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 { @@ -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); + } } diff --git a/app/src/main/java/com/devlin_n/magicplayer/VodPlayerActivity.java b/app/src/main/java/com/devlin_n/magicplayer/VodPlayerActivity.java index de47c382..7d110226 100644 --- a/app/src/main/java/com/devlin_n/magicplayer/VodPlayerActivity.java +++ b/app/src/main/java/com/devlin_n/magicplayer/VodPlayerActivity.java @@ -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; /** * 点播播放 @@ -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"; @@ -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 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(); } @@ -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(); } } @@ -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); } } diff --git a/app/src/main/res/layout/activity_live_player.xml b/app/src/main/res/layout/activity_live_player.xml index 74cac4cf..11a5ffda 100644 --- a/app/src/main/res/layout/activity_live_player.xml +++ b/app/src/main/res/layout/activity_live_player.xml @@ -4,8 +4,8 @@ android:layout_height="match_parent" android:orientation="vertical"> - diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 0b146b74..71ec6c17 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,27 +1,37 @@ + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> +