2023年7月7日发(作者:)
Java代码部分:
import ption;
import ;
import ty;
import t;
import tFoundException;
import anager;
import layer;
import eringUpdateListener;
import letionListener;
import ;
import r;
import ureListener;
import y;
import Event;
import eHolder;
import eView;
import ;
import ;
import Manager;
import kListener;
import hListener;
import utton;
import Layout;
import Params;
import indow;
import r;
import BarChangeListener;
import ew;
import ;
public class PlayVideo extends Activity implements
OnGestureListener,
OnClickListener,// 监听
OnBufferingUpdateListener,// 当网络缓冲数据流变化的时候唤起的播放事件
OnCompletionListener,// 当媒体资源在播放的时候到达终点时唤起的播放事件
aredListener,
ck// 回调函数
{
// 视频高和宽
int videoWidth;
int videoHeight;
// 按钮
ImageButton play;
//定义快进按钮
ImageButton fastPlay;
//定义快退按钮
ImageButton fastBack;
// 控制栏
LinearLayout layout_control;
LinearLayout layout_prograss;
LinearLayout videoBack;
// 用来播放媒体
MediaPlayer
// 显示媒体
SurfaceView
mediaPlayer;
surView;
// 用来控制SurfaceView
SurfaceHolder surHolder;
// 路径
String path;
// 是否是播放状态
boolean boTing = true;
//获取播放的位置
int num;
//点击屏幕次数
int count;
//第一次点击
int firClick;
//第二次点击
int secClick;
//通过flag判断是否全屏
boolean flag;
//播放进度条
SeekBar seekbar;
//显示时间组建
TextView showTime;
//播放文件的时间
int minute;
int second;
//进度条进度
int progress;
//线程控制
MyThread mt;
//声音控制
SeekBar sound;
//声音进度
int soundId;
//显示音量
TextView showSound;
//接取拖动进度条
int videoLength;
boolean f = true;
//播放尺寸
//按钮隐藏时间
int hint = 5000;
//用于接取点击ListView位置
int position;
//声称随机数
Random random;
//通过buttonFlag判断按钮背景
boolean buttonFlag = true;
//显示视频总时间
TextView allTime;
TextView distant;
PopupWindow popuWindow;
View view;
boolean popFlag ;
public void onCreate(Bundle savedInstanceState) {
te(savedInstanceState);
requestWindowFeature(E_NO_TITLE);
dow().setFlags(_FULLSCREEN,
_FULLSCREEN);
setContentView();
// 产生对象
view = outInflater().inflate(ndow, null);
//得到布局的ID
videoBack = (LinearLayout)ewById(ack);
// 产生对象
play = (ImageButton) ewById(_bu_bofang);
layout_control = (LinearLayout)findViewById(_control);
layout_prograss= (LinearLayout)findViewById(_prograss);
seekbar = (SeekBar)ewById(r);
showTime = (TextView)ewById(me);
fastPlay = (ImageButton)ewById(ay);
fastBack = (ImageButton)ewById(ck);
sound = (SeekBar)ewById();
showSound = (TextView)ewById(und);
surView = (SurfaceView) findViewById(eview_1);
allTime = (TextView)ewById(e);
distant = (TextView)findViewById(t); surHolder = der();
popuWindow = new
_PARENT,_CONTENT);
// 设置回调函数
lback(this);
PopupWindow(view,
// 设置风格
e(E_TYPE_PUSH_BUFFERS);
//bu_ibility(BLE);
// 设置按键监听
lickListener(this);
//快进监听
lickListener(this);
//快退按钮监听
lickListener(this);
//new随机数对象
random = new Random();
//接取到播放列表中点击的位置
position = on;
try {
//获取ShareActivity上下文
t = createPackageContext("",
T_IGNORE_SECURITY);
= redPreferences("setupadapter",
_WORLD_READABLE);
= ();
} catch (NameNotFoundException e) {
tackTrace();
}
//对读取的信息进行判断
if (ing("hinttime", "5秒").equals("5秒")) {
hint = 5000;
}
if (ing("hinttime", "5秒").equals("10秒")) {
hint = 10000;
}
if (ing("hinttime", "5秒").equals("15秒")) {
hint = 15000;
}
//设置全屏播放
ouchListener(new OnTouchListener() { @Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
// ptyMessageAtTime(0x11, 3000);
if(_DOWN == ion()){
count++;
if(count == 1){
new countClear().start();
firClick = (int) tTimeMillis();
if (!popFlag) {
// // // popuWindow = new PopupWindow(view,
_PARENT,_CONTENT);
Location(view, , 0, 0);
popFlag = true;
Messages(0x11);
ptyMessageDelayed(0x11, hint);
}
//设置layout显示
// if (!flag) {
/* layout_ibility(E);
layout_ibility(E);*/
//点击surfaceView延时3S发送信息
/* Messages(0x11);
ptyMessageDelayed(0x11, hint);*/
// }
} else if (count == 2){
secClick = (int) tTimeMillis();
if(secClick - firClick < 1000){
flag = !flag;
count = 0;
}
if(flag){
ght(0);
outParams(new
Params(_PARENT, _PARENT));
edSize(480, 760);
if (!popFlag) {
// popuWindow = new PopupWindow(view,
_PARENT,_CONTENT); Location(view, , 0,
0);
popFlag = true;
Messages(0x11);
ptyMessageDelayed(0x11, hint);
}
// 开始播放
// ();
}else{
if (ing("size", "4:3").equals("4:3")) {
outParams(new
Params(_PARENT, 360));
edSize(480, 360);
ght(250);
if (!popFlag) {
// popuWindow = new PopupWindow(view,
_PARENT,_CONTENT);
Location(view,
, 0, 0);
popFlag = true;
Messages(0x11);
ptyMessageDelayed(0x11, hint);
}
}
if (ing("size", "4:3").equals("16:9")) {
outParams(new
Params(_PARENT, 270));
edSize(480, 270);
ght(250);
if (!popFlag) {
// popuWindow = new PopupWindow(view,
_PARENT,_CONTENT);
Location(view,
, 0, 0);
popFlag = true;
Messages(0x11);
ptyMessageDelayed(0x11, hint);
}
}
}
count = 0;
firClick = 0;
secClick = 0;
//
});
}
}
return true;
}
//监听进度条进度
eekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
videoLength = gress();
// int q = rentPosition();
(videoLength);
//
}
//获取进度条当前的位置
int dest = gress();
//设置播放器当期的播放位置
(num);
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
//得到seekbar的进度
/* gress(progress);
videoLength = gress();*/
}
});
eekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
int i= gress();
ume(i/100f,i/100f);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
int i= gress();
t("音量:"+i);
Messages(0x11);
ptyMessageDelayed(0x11, hint);
}
});
}
private void playVideo(){
// 构建MediaPlayer对象
mediaPlayer = new MediaPlayer();
try {
// 设置媒体文件路径
aSource();
// 设置通过SurfaceView来显示画面
play(surHolder);
// 准备
e();
ght(200);
// 设置事件监听
ufferingUpdateListener(this);
ompletionListener(this);
reparedListener(this);
ioStreamType(_MUSIC);
(ation());
//设置当前播放音量最大
soundId = gress();
ume(soundId, soundId);
t("音量:"+soundId);
mt = new MyThread();
();
ptyMessage(0x13);
int n = ation();//获得持续时间
(n);
n = n/1000;
int m = n/60;
int h = m/60;
int s = n%60; m = m%60;
t(("影片长度:"+"%02d:%02d:%02d", h,m,s));
} catch (IllegalArgumentException e) {
tackTrace();
} catch (IllegalStateException e) {
tackTrace();
} catch (IOException e) {
tackTrace();
}
}
// aredListener
public void onCompletion(MediaPlayer mp) {
ptyMessage(0x14);
}
// aredListener
// 这时能确保player处于Prepared状态,触发start是最合适的
public void onPrepared(MediaPlayer mp) {
if (ing("size", "4:3").equals("4:3")) {
outParams(new
Params(_PARENT, 360));
// 设置播放视频的宽度和高度
edSize(480, 360);
// 开始播放
();
}
if (ing("size", "4:3").equals("16:9")) {
// 设置播放视频的宽度和高度
outParams(new
Params(_PARENT, 270));
edSize(480, 270);
// 开始播放
();
}
}
public void surfaceCreated(SurfaceHolder holder) {
playVideo();
}
public void surfaceChanged(SurfaceHolder holder, int format, int width,
//
//
int height) {
}
protected void onDestroy()
{
roy();
if (mediaPlayer != null)
{
e();
mediaPlayer = null;
}
//关闭cursor
();
//关闭数据库
();
//改变线程循环条件
f = false;
Messages(0x11);
s();
}
public void onClick(View v) {
if(v==play){
}
//如果正在播放
if (buttonFlag) {
geResource(_1);
();
buttonFlag = false;
}else{
geResource(_1);
();
buttonFlag = true;
}
Messages(0x11);
ptyMessageDelayed(0x11, hint);
if (v == fastPlay) {
int i = rentPosition()+5000;
(i);
gress(i);
Messages(0x11);
ptyMessageDelayed(0x11, hint);
} if (v == fastBack) {
int i = rentPosition()-5000;
(i);
gress(i);
Messages(0x11);
ptyMessageDelayed(0x11, hint);
}
}
Handler handler = new Handler(){
public void handleMessage(e msg) {
if ( == 0x11) {
if(ing()&&f){
s();
popFlag = false;
}
////启动后设置layout隐藏
/* layout_ibility(BLE);
layout_ibility(BLE);*/
}
if ( == 0x12) {
if(mediaPlayer!=null){
num = rentPosition();
}
gress(num);
// 为时 分 秒赋值
num = num/1000;
int minute = num/60;
int hour = minute/60;
int second = num%60;
minute = minute%60;
/* if (mediaPlayer!=null) {
gress(rentPosition());
}*/
t(("播放进度:"+"%02d:%02d:%02d",
hour,minute,second));
// ptyMessage(0x12);
}
if ( == 0x14) {
if (ing("playstyle","顺序播放").equals("单曲循环")) {
//
}
//释放播放的视频
e();
//游标移动到点击ListView位置
Position(on);
//在数据库中取出ListView点击的路径
= ing(1);
//播放视频
playVideo();
if (ing("playstyle", "顺序播放").equals("顺序播放")) {
//释放当前的MediaPlayer
e();
}
//自加
position ++;
if (position==nt()) {
position = 0;
}
//游标向下移动
Position(position);
//取出移动后的视频路径
= ing(1);
//播放视频
playVideo();
if (ing("playstyle", "顺序播放").equals("随机播放")) {
//释放播放的视频
e();
int r = t(nt()-1);
Position(r);
//在数据库中取出ListView点击的路径
= ing(1);
//播放视频
playVideo();
}
}
};
};
class MyThread extends Thread{
@Override
public void run() {
}
ptyMessageDelayed(0x11, hint);
// if (ation()+"".equals("0") ) {
while (f) {
try {
sleep(1000);
ptyMessage(0x12);
}catch (InterruptedException e) {
// TODO Auto-generated catch block
tackTrace();
}
}
// }
}
class countClear extends Thread{
@Override
public void run() {
try {
sleep(1000);
//睡一秒后count清0
count = 0;
} catch (InterruptedException e) {
// TODO Auto-generated catch block
tackTrace();
}
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// TODO Auto-generated method stub
}
@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
// TODO Auto-generated method stub
}
@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
}
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
配置文件:
文件
android:id="@+id/videoback" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#00000000" android:id="@+id/distant"/> android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="300px" android:layout_gravity="center_horizontal" />
配置文件
android:id="@+id/videoback" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > android:id="@+id/layout_prograss" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:orientation="vertical" > android:id="@+id/seekbar" android:layout_width="match_parent" android:layout_height="8px" android:progressDrawable="@drawable/seekbar" android:thumb="@drawable/seekbutton" android:progress="0" /> android:id="@+id/showtime" android:layout_width="match_parent" android:layout_height="wrap_content" /> android:id="@+id/alltime" android:layout_width="match_parent" android:layout_height="wrap_content" /> android:id="@+id/sound" android:layout_width="match_parent" android:layout_height="8px" android:progressDrawable="@drawable/seekbar" android:thumb="@drawable/seekbutton" android:progress="50" /> android:id="@+id/showsound" android:layout_width="match_parent" android:layout_height="wrap_content" /> android:id="@+id/layout_control" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:orientation="horizontal" > android:id="@+id/fastback" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:background="#00000000" android:scaleType="fitCenter" android:src="@drawable/stepback" /> android:id="@+id/video_bu_bofang" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:background="#00000000" android:scaleType="fitCenter" android:src="@drawable/play_1" /> android:id="@+id/fastplay" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:background="#00000000" android:scaleType="fitCenter" android:src="@drawable/stepfor" />
发布者:admin,转转请注明出处:http://www.yc00.com/web/1688675428a161689.html
评论列表(0条)