我正在开发一个视频流应用程序,但我被困在下载视频在Android应用程序,我想下载的视频在后台完全像vimeo应用程序,在vimeo应用程序如果你想下载视频,它将启动视频下载在另一个屏幕(下载屏幕)在后台,如果你进入下载屏幕,它已经开始了视频下载,还有一件事是,如果你遍历了应用程序,它仍然下载的视频在后台的下载屏幕,当你来到下载屏幕时,它会显示更新的下载进度。
1)下载vimeo视频
2)下载画面
请给我关于下载管理器的建议
发布于 2016-08-01 23:57:37
Vimeo应用程序中下载系统的底层架构目前正处于开源过程中。如果你能等几个星期,你就可以使用它了。如果没有,还有很多其他开源的“下载”系统,比如:
最终,这些都不能满足Vimeo应用程序的确切需求,所以我们决定编写我们自己的。当答案可用时,我会尝试更新它。
发布于 2016-08-01 18:13:24
此代码用于保存到SD卡中
package com.Video.ALLTestProject;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Environment;
import android.util.Log;
public class VideoSaveSDCARD extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ProgressBack PB = new ProgressBack();
PB.execute("");
}
class ProgressBack extends AsyncTask < String, String, String > {
ProgressDialog PD;
@Override
protected void onPreExecute() {
PD = ProgressDialog.show(LoginPage.this, null, "Please Wait ...", true);
PD.setCancelable(true);
}
@Override
protected void doInBackground(String...arg0) {
DownloadFile("http://beta-vidizmo.com/hilton.mp4", "Sample.mp4");
}
protected void onPostExecute(Boolean result) {
PD.dismiss();
}
}
}
有关更多信息,请参阅此主题How can I download a video file to SD card?
发布于 2016-08-06 12:59:47
1)下载管理器
Android下载管理器是在Android2.3中引入的一项服务,用于优化对长时间下载的处理。
Download Manger处理HTTP连接并监视连接更改。使用Download是一个很好的实践。
管理器,特别是在用户会话之间下载可能会在后台继续的情况下。
这个类的实例应该通过传递DOWNLOAD_SERVICE的getSystemService(String)来获得。
通过此接口请求下载的应用程序应该注册一个广播接收器,以便ACTION_NOTIFICATION_CLICKED在用户在通知中或从下载UI中单击正在运行的下载时进行适当的处理。
2)在前台运行服务
前台服务是被认为是用户主动意识到的服务,因此不是系统在内存不足时要终止的候选服务。前台服务必须为状态栏提供通知,该通知放置在“正在进行”标题下,这意味着除非停止服务或从前台移除该服务,否则不能解除通知。
例如,从服务下载视频应设置为在前台运行,因为用户明确知道其操作。状态栏中的通知可能会指示当前下载,并允许用户启动与下载过程交互的活动。
要请求您的服务在前台运行,请调用startForeground()。此方法接受两个参数:唯一标识通知的整数和状态栏的notification。
例如:
Notification notification = new Notification(R.drawable.icon, getText(R.string.ticker_text),
System.currentTimeMillis());
Intent notificationIntent = new Intent(this, ExampleActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(this, getText(R.string.notification_title),
getText(R.string.notification_message), pendingIntent);
startForeground(ONGOING_NOTIFICATION_ID, notification);
要从前台移除服务,请调用stopForeground()。此方法接受一个布尔值,指示是否也删除状态栏通知。此方法不会停止服务。但是,如果您停止该服务
https://stackoverflow.com/questions/38696174
复制相似问题