异常调用时的setDataSource(的FileDescriptor)方法(失败:状态= 0x80000000的) [英] Exception when calling setDataSource(FileDescriptor) method (failed.: status=0x80000000)
问题描述
我正在开发一个视频流应用和呼叫设置的setDataSource用的FileDescriptor当我被卡住。 我希望我的应用程序来播放视频,因为它正在下载,所以一旦我得到字节的最小数目,我将这些字节到另一个文件,以便它可以在当它被下载的原始文件的另一个文件播放。
I'm developing a video streaming application and I'm getting stuck when calling set setDataSource with a FileDescriptor. I want my application to play the video as it is being downloaded, so once I get a minimum number of bytes, I move those bytes to another file so it can be played in another file while it's being downloaded in the original file.
所以,我检查,如果我能启动媒体在线播放这样的每一个数据包:
So, I check if I can start the media palyer every packet like this:
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();
}
}
这是startMediaPlayer方法code:
This is the startMediaPlayer method code:
private void startMediaPlayer() {
try {
File bufferedFile = new File(context.getCacheDir(), "playingMedia"
+ (counter++) + ".dat");
// bufferedFile is the one that'll be played
moveFile(downloadingMediaFile, bufferedFile);
mediaPlayer = createMediaPlayer(bufferedFile);
mediaPlayer.start();
playButton.setEnabled(true);
} catch (IOException e) {
Log.e(getClass().getName(), "Error initializing the MediaPlayer.",
e);
return;
}
我将文件与以下code:
I move the file with the following code:
public void moveFile(File oldLocation, File newLocation) throws IOException {
if (oldLocation.exists()) {
BufferedInputStream reader = new BufferedInputStream(
new FileInputStream(oldLocation));
BufferedOutputStream writer = new BufferedOutputStream(
new FileOutputStream(newLocation, false));
try {
byte[] buff = new byte[8192];
int numChars;
while ((numChars = reader.read(buff, 0, buff.length)) != -1) {
writer.write(buff, 0, numChars);
}
} catch (IOException ex) {
throw new IOException("IOException when transferring "
+ oldLocation.getPath() + " to "
+ newLocation.getPath());
} finally {
try {
if (reader != null) {
writer.flush();
writer.close();
reader.close();
}
} catch (IOException ex) {
Log.e(getClass().getName(),
"Error closing files when transferring "
+ oldLocation.getPath() + " to "
+ newLocation.getPath());
}
}
} else {
throw new IOException(
"Old location does not exist when transferring "
+ oldLocation.getPath() + " to "
+ newLocation.getPath());
}
}
}
和我终于在这里创建的MediaPlayer对象:
And I finally create the MediaPlayer object here:
private MediaPlayer createMediaPlayer(File mediaFile) throws IOException {
if(mediaPlayer != null){
mediaPlayer.release();
}
MediaPlayer mPlayer = new MediaPlayer();
mPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
public boolean onError(MediaPlayer mp, int what, int extra) {
Log.e(getClass().getName(), "Error in MediaPlayer: (" + what
+ ") with extra (" + extra + ")");
return false;
}
});
// It appears that for security/permission reasons, it is better to pass
// a FileDescriptor rather than a direct path to the File.
// Also I have seen errors such as "PVMFErrNotSupported" and
// "Prepare failed.: status=0x1" if a file path String is passed to
// setDataSource().
FileInputStream fis = new FileInputStream(mediaFile);
mPlayer.reset();
FileDescriptor fd = fis.getFD();
mPlayer.setDataSource(fd); // IM GETTING THE EXCEPTION HERE
mPlayer.setDisplay(mHolder);
mPlayer.prepare();
return mPlayer;
}
这是我得到的excepction:
This is the excepction I get:
01-25 16:03:15.663: ERROR/org.pfc.utils.StreamingMediaPlayer(2229): Error initializing the MediaPlayer.
01-25 16:03:15.663: ERROR/org.pfc.utils.StreamingMediaPlayer(2229): java.io.IOException: setDataSourceFD failed.: status=0x80000000
01-25 16:03:15.663: ERROR/org.pfc.utils.StreamingMediaPlayer(2229): at android.media.MediaPlayer.setDataSource(Native Method)
01-25 16:03:15.663: ERROR/org.pfc.utils.StreamingMediaPlayer(2229): at android.media.MediaPlayer.setDataSource(MediaPlayer.java:854)
01-25 16:03:15.663: ERROR/org.pfc.utils.StreamingMediaPlayer(2229): at org.pfc.utils.StreamingMediaPlayer.createMediaPlayer(StreamingMediaPlayer.java:266)
01-25 16:03:15.663: ERROR/org.pfc.utils.StreamingMediaPlayer(2229): at org.pfc.utils.StreamingMediaPlayer.startMediaPlayer(StreamingMediaPlayer.java:226)
01-25 16:03:15.663: ERROR/org.pfc.utils.StreamingMediaPlayer(2229): at org.pfc.utils.StreamingMediaPlayer.access$4(StreamingMediaPlayer.java:203)
01-25 16:03:15.663: ERROR/org.pfc.utils.StreamingMediaPlayer(2229): at org.pfc.utils.StreamingMediaPlayer$2.run(StreamingMediaPlayer.java:183)
01-25 16:03:15.663: ERROR/org.pfc.utils.StreamingMediaPlayer(2229): at android.os.Handler.handleCallback(Handler.java:587)
01-25 16:03:15.663: ERROR/org.pfc.utils.StreamingMediaPlayer(2229): at android.os.Handler.dispatchMessage(Handler.java:92)
01-25 16:03:15.663: ERROR/org.pfc.utils.StreamingMediaPlayer(2229): at android.os.Looper.loop(Looper.java:144)
01-25 16:03:15.663: ERROR/org.pfc.utils.StreamingMediaPlayer(2229): at android.app.ActivityThread.main(ActivityThread.java:4937)
01-25 16:03:15.663: ERROR/org.pfc.utils.StreamingMediaPlayer(2229): at java.lang.reflect.Method.invokeNative(Native Method)
01-25 16:03:15.663: ERROR/org.pfc.utils.StreamingMediaPlayer(2229): at java.lang.reflect.Method.invoke(Method.java:521)
01-25 16:03:15.663: ERROR/org.pfc.utils.StreamingMediaPlayer(2229): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-25 16:03:15.663: ERROR/org.pfc.utils.StreamingMediaPlayer(2229): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-25 16:03:15.663: ERROR/org.pfc.utils.StreamingMediaPlayer(2229): at dalvik.system.NativeStart.main(Native Method)
我在这里的整个上午卡住,我真的发现该错误的信息。有人告诉我使用的文件路径,但我得到了其他例外,我在评论中谈论(右过的FileInputStream创建)。
I've been the whole morning stuck here and I really find no information on that error. Some people have told me to use the file path, but I get the other exception I talk about in the comments (right over the FileInputStream creation).
我真的丢在这里,任何帮助将是非常pciated AP $ P $
I'm really lost here, any help would be very appreciated
推荐答案
好了,我已经到了这样的结论类似的错误:
Okay, I've arrived to the conclusion that errors like:
prepare失败:状态=为0x1(当调用prepare())
Prepare failed.: status=0x1 (when calling prepare() )
和
setDataSourceFD失败:状态= 0x80000000的(调用setDataSourceFD时,())
setDataSourceFD failed.: status=0x80000000 (when calling setDataSourceFD() )
都与文件格式,可能意味着该文件不完整,损坏或类似的东西...
have to do with the file format and probably mean that the file is incomplete, corrupted or something like that...
正如我在后<一href="http://stackoverflow.com/questions/4861805/play-video-in-android-from-a-bytes-stream/4912686#4912686">this链接,我发现当它流(虽然我用的setDataSource,不setDataSourceFD),但它会不会与大多数影片的工作。工作正常的特定的视频
As I have post in this link, I've found an specific video which works fine while streaming it (though I use setDataSource, not setDataSourceFD), but it'll not work with most of the videos.
这篇关于异常调用时的setDataSource(的FileDescriptor)方法(失败:状态= 0x80000000的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!