我正在开发一个视频流应用程序,并且在使用FileDescriptor调用set setDataSource时遇到困难.我希望我的应用程序在下载时播放视频,所以一旦我得到最小字节数,我将这些字节移动到另一个文件,这样它就可以在原始文件中下载时在另一个文件中播放.
所以,我检查一下我是否可以像这样启动每个数据包的媒体:
if (mediaPlayer == null) {
// Only create the MediaPlayer once we have the minimum
// buffered data
if (totalKbRead >= INTIAL_KB_BUFFER) {
try {
startMediaPlayer();
} catch (Exception e) {
Log.e(getClass().getName(),
"Error copying buffered conent.", e);
}
}
} else if (mediaPlayer.getDuration()
- mediaPlayer.getCurrentPosition() <= 1000) {
transferBufferToMediaPlayer();
}
}
Run Code Online (Sandbox Code Playgroud)
这是startMediaPlayer方法代码:
private void startMediaPlayer() {
try {
File bufferedFile = new File(context.getCacheDir(), "playingMedia"
+ (counter++) + ".dat");
// bufferedFile is the one that'll be played
moveFile(downloadingMediaFile, …Run Code Online (Sandbox Code Playgroud) 我希望我的应用程序打开一个纯文本文件,我的终端上安装了任何文件编辑器,但我不断收到此异常:
ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.EDIT dat=file:///sdcard/folder/file.txt }
Run Code Online (Sandbox Code Playgroud)
首先我认为我没有安装文件编辑器,但如果我使用ASTRO文件管理器,我可以使用"文件编辑器"和"QuickOffice"打开文件,所以我认为问题是我没有使用正确的代码......
这是代码
Intent intent = new Intent(Intent.ACTION_EDIT);
Uri uri = Uri.parse("file:///sdcard/folder/file.txt");
intent.setDataAndType(uri, "plain/text");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
更令人惊讶的是,如果我使用不存在的文件的路径,它会不断引发相同的异常......
谢谢
我想知道我是否可以启动一个Intent来查看带有文件浏览器的目录(如果设备上安装了一个),那么我可以打开这样的文件夹:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file:///sdcard/MyFolder");
intent.setDataAndType(uri, "MIME TYPE FOR FOLDERS");
startActivity(intent);
Run Code Online (Sandbox Code Playgroud) 有没有办法从Android中的字节流播放视频?我正在使用特定的通信中间件,所以我不能只将http/rtsp链接传递给MediaPlayer对象.
我想知道我是否可以使用本地http/rtsp链接包装我的流,这样我就可以播放流而不是等到文件下载才能播放.
我的中间件通过TCP工作,所以我也认为我可以用tcp数据报包装我的rtsp数据报,并在删除TCP头后以某种方式在客户端解释它们.
我真的很惊讶我不能只将字节流传递给MediaPlayer.提前致谢.
我正在开发一个面向群组的网络应用程序.问题是,当我即将加入一个组时,它首先检查该组是否安全,如果是,它会询问用户和密码.获得组安全性可能需要几秒钟,因此我为整个过程生成了一个新线程.如果该组需要安全性,我想弹出一个Dialog.我认为它可能与后台线程有关,它们可能无法弹出Dialogs ......但问题是我需要在后台线程中检查组安全性,因为它需要一些时间.
希望任何人都可以提出解决方案或任何方式只在组安全时询问用户/通过.这是后台主题:
public void run() {
secInf = mGroupId.getSecurityInformation();
if (secInf.getAdmissionLevel() == CreateGroupDialog.PRIVATE_KEY_ACCESS) {
showUserPasswordDialog();
} else {
mService.joinGroup(mGroupId);
// Notifies handler to dismiss ProgresDialog and start activity
mHandler.sendMessage(Message.obtain(mHandler,
GroupsActivity.JOIN_SUCCESSFUL));
}
Run Code Online (Sandbox Code Playgroud)
showUserPasswordDialog的用途(mActivity是产生此线程的活动):
private void showUserPasswordDialog() {
AlertDialog dialog;
// add this to your code
// This example shows how to add a custom layout to an AlertDialog
LayoutInflater factory = LayoutInflater.from(mActivity);
final View textEntryView = factory.inflate(
R.layout.alert_dialog_text_entry, null);
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
builder.setIcon(R.drawable.alert_dialog_icon);
builder.setTitle(R.string.ask_user_password);
builder.setView(textEntryView);
builder.setPositiveButton(R.string.ok_text,
new DialogInterface.OnClickListener() …Run Code Online (Sandbox Code Playgroud)