package com.qiniu.qlive.activity.widget;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.media.AudioManager;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.TextView;
import com.pili.pldroid.player.IMediaController;
import java.util.Locale;
/**
* Created by jerikc on 15/5/29.
*/
public class MediaController extends FrameLayout implements IMediaController {
private static final String TAG = "MyMediaController";
private static final int SEEK_TO_POST_DELAY_MILLIS = 200;
private static final int FADE_OUT = 1;
private static final int SHOW_PROGRESS = 2;
private static final int IC_MEDIA_PAUSE_ID = Resources.getSystem().getIdentifier("ic_media_pause", "drawable", "android");
private static final int IC_MEDIA_PLAY_ID = Resources.getSystem().getIdentifier("ic_media_play", "drawable", "android");
private static final int MEDIA_CONTROLLER_ID = Resources.getSystem().getIdentifier("media_controller", "layout", "android");
private static final int PRV_BUTTON_ID = Resources.getSystem().getIdentifier("prev", "id", "android");
private static final int FFWD_BUTTON_ID = Resources.getSystem().getIdentifier("ffwd", "id", "android");
private static final int NEXT_BUTTON_ID = Resources.getSystem().getIdentifier("next", "id", "android");
private static final int REW_BUTTON_ID = Resources.getSystem().getIdentifier("rew", "id", "android");
private static final int PAUSE_BUTTON_ID = Resources.getSystem().getIdentifier("pause", "id", "android");
private static final int MEDIACONTROLLER_PROGRESS_ID = Resources.getSystem().getIdentifier("mediacontroller_progress", "id", "android");
private static final int END_TIME_ID = Resources.getSystem().getIdentifier("time", "id", "android");
private static final int CURRENT_TIME_ID = Resources.getSystem().getIdentifier("time_current", "id", "android");
private static int sDefaultTimeout = 3000;
private MediaPlayerControl mPlayer;
private Context mContext;
private PopupWindow mWindow;
private int mAnimStyle;
private View mAnchor;
private View mRoot;
private ProgressBar mProgress;
private TextView mEndTime, mCurrentTime;
private long mDuration;
private boolean mShowing;
private boolean mDragging;
private boolean mInstantSeeking = true;
private boolean mFromXml = false;
private ImageButton mPauseButton;
private ImageButton mFfwdButton;
private ImageButton mRewButton;
private ImageButton mNextButton;
private ImageButton mPrevButton;
private boolean mUseFastForward;
private AudioManager mAM;
private Runnable mLastSeekBarRunnable;
private boolean mDisableProgress = false;
private OnShownListener mShownListener;
private OnHiddenListener mHiddenListener;
@SuppressLint("HandlerLeak")
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
long pos;
switch (msg.what) {
case FADE_OUT:
hide();
break;
case SHOW_PROGRESS:
pos = setProgress();
if (!mDragging && mShowing) {
msg = obtainMessage(SHOW_PROGRESS);
sendMessageDelayed(msg, 1000 - (pos % 1000));
updatePausePlay();
}
break;
}
}
};
private OnClickListener mPauseListener = new OnClickListener() {
public void onClick(View v) {
doPauseResume();
show(sDefaultTimeout);
}
};
private SeekBar.OnSeekBarChangeListener mSeekListener = new SeekBar.OnSeekBarChangeListener() {
public void onStartTrackingTouch(SeekBar bar) {
mDragging = true;
show(3600000);
mHandler.removeMessages(SHOW_PROGRESS);
if (mInstantSeeking)
mAM.setStreamMute(AudioManager.STREAM_MUSIC, true);
}
public void onProgressChanged(SeekBar bar, int progress, boolean fromuser) {
if (!fromuser)
return;
final long newposition = (mDuration * progress) / 1000;
String time = generateTime(newposition);
if (mInstantSeeking) {
mHandler.removeCallbacks(mLastSeekBarRunnable);
mLastSeekBarRunnable = new Runnable() {
@Override
public void run() {
mPlayer.seekTo(newposition);
}
};
mHandler.postDelayed(mLastSeekBarRunnable, SEEK_TO_POST_DELAY_MILLIS);
}
if (mCurrentTime != null)
mCurrentTime.setText(time);
}
public void onStopTrackingTouch(SeekBar bar) {
if (!mInstantSeeking)
mPlayer.seekTo((mDuration * bar.getProgress()) / 1000);
show(sDefaultTimeout);
mHandler.removeMessages(SHOW_PROGRESS);
mAM.setStreamMute(AudioManager.STREAM_MUSIC, false);
mDragging = false;
mHandler.sendEmptyMessageDelayed(SHOW_PROGRESS, 1000);
}
};
private View.OnClickListener mRewListener = new View.OnClickListener() {
public void onClick(View v) {
long pos = mPlayer.getCurrentPosition();
pos -= 5000; // milliseconds
mPlayer.seekTo(pos);
setProgress();
show(sDefaultTimeout);
}
};
private View.OnClickListener mFfwdListener = new View.OnClickListener() {
public void onClick(View v) {
long pos = mPlayer.getCurrentPosition();
pos += 15000; // milliseconds
mPlayer.seekTo(pos);
setProgress();
show(sDefaultTimeout);
}
};
public MediaController(Context context, AttributeSet attrs) {
super(context, attrs);
mRoot = this;
mFromXml = true;
initController(context);
}
public MediaController(Context context) {
super(context);
if (!mFromXml && initController(context))
initFloatingWindow();
}
public MediaController(Context context, boolean useFastForward, boolean disableProgressBar) {
this(context);
mUseFastForward = useFastForward;
mDisableProgress = disableProgressBar;
}
public MediaController(Context context, boolean useFastForward) {
this(context);
mUseFastForward = useFastForward;
}
private static String generateTime(long position) {
int totalSeconds = (int) (position / 1000);
int seconds = totalSeconds % 60;
int minutes = (totalSeconds / 60) % 60;
int hours = totalSeconds / 3600;
if (hours > 0) {
return String.format(Locale.US, "%02d:%02d:%02d", hours, minutes,
seconds).toString();
} else {
return String.format(Locale.US, "%02d:%02d", minutes, seconds)
.toString();
}
}
private boolean initController(Context context) {
mUseFastForward = true;
mContext = context;
mAM = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
return true;
}
@Override
public void onFinishInflate() {
if (mRoot != null)
initControllerView(mRoot);
}
private void initFloatingWind
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
为了满足广大Android开发爱好者与从业者的学习需求,我们精心整理并上传了一份全面而实用的Android项目资源包。这份资源包内容丰富,涵盖了从基础知识到实战应用的全方位内容,旨在为开发者们提供一个便捷、高效的学习平台。 一、文件手册 资源包中的文件手册部分,详细记录了Android开发的核心知识点和常用技术。无论是初学者还是有一定经验的开发者,都能从中找到所需的学习资料。手册采用了简洁明了的排版方式,使得查阅更加方便快捷。同时,手册内容深入浅出,既适合新手入门,也能为老手提供有价值的参考。 二、项目实战与练习 为了让学习者能够将理论知识与实践相结合,我们特别准备了项目实战与练习部分。这部分内容包含了多个精心设计的Android项目案例,从需求分析、设计思路到实现过程,都有详细的讲解和代码示例。学习者可以通过实际操作,深入了解Android开发的整个流程,提升自己的实战能力。 此外,我们还提供了一系列练习题,旨在巩固所学知识,检验学习成果。这些练习题既有基础题,也有难度较高的挑战题,适合不同层次的学习者进行练习。 三、Android开发工具集 在Android开发过程中,选择合适的工具能够大大提高开发效率。因此,我们整理了常用的Android开发工具集,包括开发工具、测试工具、性能优化工具等。这些工具都是经过我们精心筛选和测试的,能够帮助开发者们更加高效地进行Android开发工作。 总的来说,这份Android项目资源包是一份不可多得的学习资料,无论你是初学者还是有一定经验的开发者,都能从中受益匪浅。我们希望通过这份资源包,为广大Android开发爱好者与从业者提供一个更加便捷、高效的学习平台,共同推动Android开发领域的发展。
资源推荐
资源详情
资源评论
收起资源包目录
七牛直播demo项目Android版本.zip (127个子文件)
gradlew.bat 2KB
.gitignore 280B
build.gradle 894B
build.gradle 436B
settings.gradle 15B
gradlew 5KB
app.iml 8KB
QLive.iml 911B
pldroid-camera-streaming-1.4.1.jar 124KB
ijkmediaplayer.jar 42KB
pldroid-player-1.1.4.jar 37KB
MediaController.java 18KB
SWCodecCameraStreamingActivity.java 13KB
StreamingBaseActivity.java 9KB
LiveInfoActivity.java 9KB
MainActivity.java 8KB
VideoListService.java 7KB
LiveVideoListFragment.java 7KB
LiveStreamListFragment.java 7KB
MyLiveVideoListActivity.java 6KB
LiveStreamService.java 5KB
SignupActivity.java 5KB
LoginActivity.java 4KB
VideoPlayService.java 4KB
VideoPlayActivity.java 3KB
UserService.java 3KB
MyChannelFragment.java 3KB
Tools.java 3KB
Remote.java 1KB
MainActivityEventHandler.java 1KB
Account.java 853B
APICode.java 719B
LiveVideo.java 706B
VideoPlayResult.java 580B
LoginResult.java 544B
ApiResult.java 513B
GetStreamResult.java 460B
VideoListResult.java 423B
Session.java 381B
User.java 372B
ApplicationTest.java 349B
StartPublishResult.java 337B
AsyncRun.java 323B
Config.java 289B
ActionID.java 246B
LiveTask.java 240B
StreamQuality.java 215B
SignupResult.java 210B
StopPublishResult.java 181B
StreamStatus.java 174B
LICENSE 18KB
ic_launcher.png 9KB
ic_action_switch_camera.png 6KB
ic_launcher.png 6KB
ic_person.png 4KB
ic_launcher.png 4KB
ic_action_refresh.png 3KB
ic_action_crop.png 3KB
ic_launcher.png 2KB
ic_action_refresh.png 2KB
ic_action_switch_camera.png 2KB
ic_person.png 2KB
ic_action_refresh.png 2KB
ic_action_flash_off.png 1KB
ic_action_switch_camera.png 1KB
ic_action_refresh.png 1KB
ic_action_crop.png 1KB
ic_person.png 1004B
ic_action_flash_on.png 998B
ic_action_flash_off.png 889B
ic_action_flash_off.png 889B
ic_action_flash_off.png 889B
ic_action_switch_camera.png 814B
ic_action_flash_on.png 612B
ic_action_flash_on.png 612B
ic_action_flash_on.png 612B
ic_action_crop.png 609B
ic_person.png 573B
ic_action_crop.png 389B
proguard-rules.pro 662B
gradle.properties 855B
local.properties 433B
libpldroidplayer.so 2.32MB
libpldroid_streaming_h264_encoder.so 866KB
libpldroid_streaming_h264_encoder.so 589KB
libpldroid_streaming_aac_encoder.so 137KB
libpldroid_streaming_core.so 105KB
libpldroid_streaming_aac_encoder.so 105KB
libpldroid_streaming_core.so 105KB
libpldroid_streaming_core.so 77KB
libpldroid_streaming_core.so 69KB
AndroidManifest.xml 4KB
activity_camera_streaming.xml 3KB
activity_signup.xml 2KB
activity_live_info.xml 2KB
fragment_my_channel.xml 2KB
strings.xml 2KB
activity_login.xml 2KB
list_item_video.xml 2KB
dimens.xml 897B
共 127 条
- 1
- 2
资源评论
01红C
- 粉丝: 1906
- 资源: 2111
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功