Skip to content

Commit

Permalink
为锁定屏幕添加Toast提示
Browse files Browse the repository at this point in the history
  • Loading branch information
Doikki committed May 20, 2017
1 parent 862c9ea commit 73ace13
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 26 deletions.
16 changes: 10 additions & 6 deletions app/src/main/java/com/devlin_n/magicplayer/VodPlayerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
import android.widget.Toast;

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

import java.util.ArrayList;
import java.util.List;

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

Expand Down Expand Up @@ -40,18 +44,18 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
// int widthPixels = getResources().getDisplayMetrics().widthPixels;
// 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));
List<VideoModel> videos = new ArrayList<>();
videos.add(new VideoModel(URL_AD, "广告", MagicVideoView.AD));
videos.add(new VideoModel(URL_VOD, "网易公开课-如何掌控你的自由时间", MagicVideoView.VOD));

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,14 @@ protected String stringForTime(int timeMs) {
protected void onAttachedToWindow() {
super.onAttachedToWindow();
post(mShowProgress);
updatePlayButton();
}

@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
updatePlayButton();
protected void onWindowVisibilityChanged(int visibility) {
super.onWindowVisibilityChanged(visibility);
if (visibility == VISIBLE) {
post(mShowProgress);
}
}

public interface MediaPlayerControlInterface {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import com.devlin_n.magic_player.R;
import com.devlin_n.magic_player.player.MagicVideoView;
Expand Down Expand Up @@ -101,10 +102,12 @@ private void doLockUnlock() {
mShowing = false;
show();
lock.setSelected(false);
Toast.makeText(getContext(), R.string.unlocked, Toast.LENGTH_SHORT).show();
} else {
hide();
isLocked = true;
lock.setSelected(true);
Toast.makeText(getContext(), R.string.locked, Toast.LENGTH_SHORT).show();
}
mediaPlayer.setLock(isLocked);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ public void onWindowFocusChanged(boolean hasFocus) {
if (hasFocus && originalWidth == 0 && originalHeight == 0) {
originalWidth = getWidth();
originalHeight = getHeight();
if (mMediaController != null) {
mMediaController.setLayoutParams(new LayoutParams(originalWidth, originalHeight));
}
}
}

Expand Down Expand Up @@ -440,7 +443,7 @@ public int getBufferPercentage() {
public void startFloatWindow() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {//Android M 以上系统需要请求权限
if (!Settings.canDrawOverlays(WindowUtil.getAppCompActivity(getContext()))) {
Toast.makeText(WindowUtil.getAppCompActivity(getContext()), R.string.float_window_warning, Toast.LENGTH_SHORT).show();
Toast.makeText(WindowUtil.getAppCompActivity(getContext()), R.string.float_window_warning, Toast.LENGTH_LONG).show();
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + WindowUtil.getAppCompActivity(getContext()).getPackageName()));
WindowUtil.getAppCompActivity(getContext()).startActivityForResult(intent, ALERT_WINDOW_PERMISSION_CODE);
Expand Down Expand Up @@ -683,7 +686,11 @@ public boolean onInfo(IMediaPlayer iMediaPlayer, int what, int extra) {
case IjkMediaPlayer.MEDIA_INFO_AUDIO_RENDERING_START:
mCurrentState = STATE_PLAYING;
bufferProgress.setVisibility(View.GONE);
if (mMediaController != null) mMediaController.updatePlayButton();
if (mMediaController != null && !isControllerAdded) {
controllerContainer.addView(mMediaController);
isControllerAdded = true;
mMediaController.updatePlayButton();
}
if (mTargetState == STATE_PAUSED) pause();
break;
}
Expand All @@ -701,17 +708,6 @@ public void onPrepared(IMediaPlayer iMediaPlayer) {
if (mCurrentPosition > 0 && mCurrentVideoType == VOD) {
seekTo(mCurrentPosition);
}
if (mMediaController != null && !isControllerAdded) {
if (isFullScreen) {
mMediaController.setLayoutParams(new LayoutParams(WindowUtil.getScreenWidth(getContext()),
WindowUtil.getScreenHeight(getContext(), false)));
mMediaController.updateFullScreen();
} else {
mMediaController.setLayoutParams(new LayoutParams(originalWidth, originalHeight));
}
controllerContainer.addView(mMediaController);
isControllerAdded = true;
}
}

@Override
Expand All @@ -729,11 +725,10 @@ public void onVideoSizeChanged(IMediaPlayer iMediaPlayer, int i, int i1, int i2,
public boolean onBackPressed() {
if (mMediaController != null && isLocked) {
mMediaController.show();
Toast.makeText(getContext(), R.string.lock_tip, Toast.LENGTH_SHORT).show();
return true;
}
if (mAlwaysFullScreen) {
return false;
}
if (mAlwaysFullScreen) return false;
if (isFullScreen) {
stopFullScreen();
WindowUtil.getAppCompActivity(getContext()).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Expand Down
3 changes: 3 additions & 0 deletions magic_player/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@
<string name="retry">重 试</string>
<string name="continue_play">继续播放</string>
<string name="wifi_tip">您正在使用移动网络,继续播放将消耗流量</string>
<string name="lock_tip">请先解锁屏幕!</string>
<string name="unlocked">已解锁</string>
<string name="locked">已锁定</string>
</resources>

0 comments on commit 73ace13

Please sign in to comment.