/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.android.media;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.URLUtil;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.VideoView;
public class VideoViewDemo extends Activity {
private static final String TAG = "VideoViewDemo";
private VideoView mVideoView;
//private AudioPlayer mVideoView;
private EditText mPath;
private ImageButton mPlay;
private ImageButton mPause;
private ImageButton mReset;
private ImageButton mStop;
private String current;
////////////////////////////////
private boolean wasPlaying;
private MediaPlayer mPlayer;
private static final int MIN_BUFF = 2000 * 1024;
private static final int REC_BUFF = 500 * 1024;
private Handler handler = new Handler();
private File DLTempFile;
private final String TEMP_DOWNLOAD_FILE_NAME = "tempMediaData";
private final String TEMP_BUFF_FILE_NAME = "tempBufferData";
private final String FILE_POSTFIX = ".mp4";
private final int PER_READ = 1024;
private boolean pause=false;
private boolean stop;
private final int UNKNOWN_LENGTH = -1;
private Handler mHandler = null;
private TextView playedTextView=null;
private TextView downtext =null;
private int VideoDuraton = 1; //总时间
private int curPosition;
private int mediaLength = 1; //文件总长度
private int totalKbRead = 0; //已经下载的长度
private boolean downloadOver = false;
private boolean wasPlayed = false;
private SeekBar seekbar = null;
private boolean localfile = false;
private double downper = 0.00; // 下载百分比
private double playper = 0.00; // 播放比例
private double loadper = 0.00;
////////////////////////////////
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
mVideoView = (VideoView) findViewById(R.id.surface_view);
mPath = (EditText) findViewById(R.id.path);
seekbar = (SeekBar) findViewById(R.id.seekbar);
seekbar.setMax(100);
playedTextView = (TextView) findViewById(R.id.has_played);
downtext = (TextView) findViewById(R.id.downtext);
mPath.setText("http://www.mis2036.com/0.mp4");
mPlay = (ImageButton) findViewById(R.id.play);
mPause = (ImageButton) findViewById(R.id.pause);
mReset = (ImageButton) findViewById(R.id.reset);
mStop = (ImageButton) findViewById(R.id.stop);
mVideoView.setOnPreparedListener(prepareListener);
mVideoView.setOnCompletionListener(CompletionListener);
mVideoView.setOnErrorListener(ErrorListener);
mPlay.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
final String path = mPath.getText().toString();
localfile = false;
playnew(path);
//playVideo();
/*
try {
copyFile("/sdcard/0.mp4","/sdcard/a.mp4");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
playsdcardfile("/sdcard/0.mp4");
*/
}
});
mPause.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
if (mVideoView != null) {
localfile = true;
mVideoView.setVideoPath("/sdcard/0.mp4");
myHandler.sendEmptyMessage(PROGRESS_CHANGED);
//mVideoView.pause();
}
}
});
mReset.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
if (mVideoView != null) {
//mVideoView.setVideoPath(DLTempFile.getAbsolutePath());
//mVideoView.seekTo(0);
mVideoView.stopPlayback();
DLTempFile.delete();
}
}
});
mStop.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
stop = true;
/*
if (mVideoView != null) {
current = null;
mVideoView.stopPlayback();
}
*/
}
});
runOnUiThread(new Runnable(){
public void run() {
//playVideo();
}
});
}
//播放本地文件
private void playsdcardfile(String Source){
mVideoView.setVideoPath(Source);
mVideoView.start();
}
///////////////////////////////////////////
//线程下载部分
///////////////////////////////////////////
private MediaPlayer.OnPreparedListener prepareListener = new MediaPlayer.OnPreparedListener(){
public void onPrepared(MediaPlayer mp){
Toast.makeText(VideoViewDemo.this, "准备完成"+curPosition,Toast.LENGTH_SHORT).show();
VideoDuraton=mVideoView.getDuration()+1; //获取总时间
loadper = downper; //装置的部分,就是下载的部分
myHandler.sendEmptyMessage(PROGRESS_CHANGED);
mVideoView.seekTo(curPosition);
mp.start(); //开始播放
}
};
//视频播放完成
private MediaPlayer.OnCompletionListener CompletionListener=new MediaPlayer.OnCompletionListener(){
@Override
public void onCompletion(MediaPlayer arg0) {
// TODO Auto-generated method stub
curPosition = 0;
mVideoView.stopPlayback();
}
};
//视频播放完成
private MediaPlayer.OnErrorListener ErrorListener=new MediaPlayer.OnErrorListener(){
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
// TODO Auto-generated method stub
mVideoView.stopPlayback();
Toast.makeText(VideoViewDemo.this, "发现错误:"+curPosition+"错误编号:"+what,Toast.LENGTH_SHORT).show();
pause = true;
return true;
}
};
public void playnew(final String path) {
downloadOver = false;
totalKbRead = 0;
try {
Log.v(TAG, "playing: " + path);
if (path.equals(current) && mPlayer != null) {
mPlayer.start();
return;
}
current = path;
mPlayer = null;
new PlayThread(current).start();
} catch (Exception e) {
}
}
public void setHandler(Handler handler) {
mHandler = handler;
}
//创建一个消息处理
private final static int PROGRESS_CHANGED = 0;
private final static int HIDE_CONTROLER = 1;
private final static int CHANGE_FULLSCREEN =2;
private final static int VIDEO_READY =3;
private final static int VIDEO_BUFFERFULL =4;
private final static int DOWN_REFRESH = 5;
Handler myHandler = new Handler(){
@Override
public void handleMessage(Message msg) {
switch(msg.what){
c
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【项目资源】:包含前端、后端、移动开发、操作系统、人工智能、物联网、信息化管理、数据库、硬件开发、大数据、课程资源、音视频、网站开发等各种技术项目的源码。包括STM32、ESP8266、PHP、QT、Linux、iOS、C++、Java、python、web、C#、EDA、proteus、RTOS等项目的源码。【项目质量】:所有源码都经过严格测试,可以直接运行。功能在确认正常工作后才上传。【适用人群】:适用于希望学习不同技术领域的小白或进阶学习者。可作为毕设项目、课程设计、大作业、工程实训或初期项目立项。【附加价值】:项目具有较高的学习借鉴价值,也可直接拿来修改复刻。对于有一定基础或热衷于研究的人来说,可以在这些基础代码上进行修改和扩展,实现其他功能。【沟通交流】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。鼓励下载和使用,并欢迎大家互相学习,共同进步。
资源推荐
资源详情
资源评论
收起资源包目录
流媒体线程下载,播放,(支持断点).zip (40个子文件)
流媒体线程下载,播放,(支持断点)
VideoView
VideoView
.classpath 287B
assets
src
org
apache
android
media
VideoViewDemo.java 20KB
VideoViewApplication.java 1014B
AudioPlayer.java 9KB
libs
res
drawable-mdpi
drawable-ldpi
values
layout
main.xml 2KB
drawable
stop.PNG 6KB
play.PNG 7KB
Thumbs.db 24KB
pause.PNG 5KB
reset.PNG 5KB
drawable-hdpi
bin
resources.ap_ 26KB
VideoViewDemo.apk 39KB
classes.dex 24KB
org
apache
android
media
VideoViewDemo.class 15KB
VideoViewDemo$PlayThread.class 1KB
AudioPlayer$PlayThread.class 2KB
VideoViewDemo$7.class 1KB
VideoViewDemo$3.class 2KB
VideoViewDemo$8.class 889B
R$layout.class 412B
VideoViewDemo$9.class 676B
AudioPlayer$1.class 679B
VideoViewDemo$5.class 1KB
R$id.class 647B
VideoViewDemo$4.class 3KB
R$attr.class 358B
VideoViewDemo$10.class 694B
R$drawable.class 504B
VideoViewDemo$6.class 1KB
VideoViewDemo$1.class 2KB
R.class 517B
VideoViewApplication.class 481B
VideoViewDemo$2.class 1KB
AudioPlayer.class 8KB
default.properties 449B
.project 849B
AndroidManifest.xml 1KB
META-INF
MANIFEST.MF 71B
gen
org
apache
android
media
R.java 1KB
VideoView.rar 142KB
共 40 条
- 1
资源评论
心梓知识
- 粉丝: 6381
- 资源: 3万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功