我有输入流,我需要将其传递给视频视图:
但它说 OutOfMemoryError
这是我的代码:
//to convert input stream to string
public static String convertStreamToString(InputStream is) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
is.close();
return sb.toString();
}
//passing that string to video view
String total = convertStreamToString(inputStream);
Uri uri = Uri.parse(total);
videoHolder.setVideoURI(uri);
如何实现这一目标?
编辑
这是堆栈跟踪
07-17 17:46:34.242: E/AndroidRuntime(5384): FATAL EXCEPTION: main
07-17 17:46:34.242: E/AndroidRuntime(5384): java.lang.OutOfMemoryError
07-17 17:46:34.242: E/AndroidRuntime(5384): at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:94)
07-17 17:46:34.242: E/AndroidRuntime(5384): at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:145)
07-17 17:46:34.242: E/AndroidRuntime(5384): at java.lang.StringBuilder.append(StringBuilder.java:216)
07-17 17:46:34.242: E/AndroidRuntime(5384): at com.abc.Utility.Utils.convertStreamToString(Utils.java:196)
07-17 17:46:34.242: E/AndroidRuntime(5384): at com.abc.xyz.VideoPlayer.onCreate(VideoPlayer.java:257)
07-17 17:46:34.242: E/AndroidRuntime(5384): at android.app.Activity.performCreate(Activity.java:4635)
07-17 17:46:34.242: E/AndroidRuntime(5384): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-17 17:46:34.242: E/AndroidRuntime(5384): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2031)
07-17 17:46:34.242: E/AndroidRuntime(5384): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2092)
07-17 17:46:34.242: E/AndroidRuntime(5384): at android.app.ActivityThread.access$600(ActivityThread.java:126)
07-17 17:46:34.242: E/AndroidRuntime(5384): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1172)
07-17 17:46:34.242: E/AndroidRuntime(5384): at android.os.Handler.dispatchMessage(Handler.java:99)
07-17 17:46:34.242: E/AndroidRuntime(5384): at android.os.Looper.loop(Looper.java:137)
07-17 17:46:34.242: E/AndroidRuntime(5384): at android.app.ActivityThread.main(ActivityThread.java:4586)
07-17 17:46:34.242: E/AndroidRuntime(5384): at java.lang.reflect.Method.invokeNative(Native Method)
07-17 17:46:34.242: E/AndroidRuntime(5384): at java.lang.reflect.Method.invoke(Method.java:511)
07-17 17:46:34.242: E/AndroidRuntime(5384): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-17 17:46:34.242: E/AndroidRuntime(5384): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-17 17:46:34.242: E/AndroidRuntime(5384): at dalvik.system.NativeStart.main(Native Method)