How to Give Assets Folder Path for Playing mp4 video? I am Using Following Code for that.
Please Help me.
String stringPath = "file:///android_asset/sample.mp4";
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDisplay(surfaceHolder);
mediaPlayer.setDataSource(stringPath);
mediaPlayer.prepare();
mediaPlayer.start();
But Above Code is Give me Following Warnings & Errors.
07-25 13:11:40.833: ERROR/MediaPlayer(11295): error (1, -2147483648)
07-25 13:11:40.833: WARN/System.err(11295): java.io.IOException: Prepare failed.: status=0x1
07-25 13:11:41.103: WARN/System.err(11295): at android.media.MediaPlayer.prepare(Native Method)
07-25 13:11:41.103: WARN/System.err(11295): at com.arthisoft.tempforvideo2.AndroidVideoPlayer.playvideo(AndroidVideoPlayer.java:69)
07-25 13:11:41.103: WARN/System.err(11295): at com.arthisoft.tempforvideo2.AndroidVideoPlayer$2.onClick(AndroidVideoPlayer.java:52)
07-25 13:11:41.113: WARN/System.err(11295): at android.view.View.performClick(View.java:2408)
07-25 13:11:41.113: WARN/System.err(11295): at android.view.View$PerformClick.run(View.java:8816)
07-25 13:11:41.123: WARN/System.err(11295): at android.os.Handler.handleCallback(Handler.java:587)
07-25 13:11:41.123: WARN/System.err(11295): at android.os.Handler.dispatchMessage(Handler.java:92)
07-25 13:11:41.123: WARN/System.err(11295): at android.os.Looper.loop(Looper.java:123)
07-25 13:11:41.134: WARN/System.err(11295): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-25 13:11:41.143: WARN/System.err(11295): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 13:11:41.143: WARN/System.err(11295): at java.lang.reflect.Method.invoke(Method.java:521)
07-25 13:11:41.143: WARN/System.err(11295): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-25 13:11:41.153: WARN/System.err(11295): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-25 13:11:41.153: WARN/System.err(11295): at dalvik.system.NativeStart.main(Native Method)
07-25 13:11:41.153: ERROR/MediaPlayer(11295): start called in state 0
07-25 13:11:41.163: ERROR/MediaPlayer(11295): error (-38, 0)
07-25 13:11:41.243: ERROR/MediaPlayer(11295): Error (-38,0)
Move the .mp4 file to raw/ folder. Then, replace your string with this:
String stringPath = "android.resource://[your_package_name]/raw/sample"
Please specify your location is in the sd card or in the internal storage. If it is in the sd card then it will be:
String stringPath = "/sdcard/android_asset/sample.mp4";
You have to do something like this
mediaPlayer.setDataSource(AndroidVideoPlayer.this, Uri
.parse("android.resource://com.arthisoft.tempforvideo2/R.raw.sample"));
Related
I have to send a byte via bluetooth, the problem is that I can not use this script because I have to write the number that is greater than 127:
mChatService.write(new byte[]{});
how can I do?
Thanks.
EDIT
Logcat:
07-25 14:18:20.410: D/AndroidRuntime(1906): Shutting down VM
07-25 14:18:20.410: W/dalvikvm(1906): threadid=1: thread exiting with uncaught exception (group=0x41607ce0)
07-25 14:18:20.410: E/AndroidRuntime(1906): FATAL EXCEPTION: main
07-25 14:18:20.410: E/AndroidRuntime(1906): Process: com.example.android.BluetoothChat, PID: 1906
07-25 14:18:20.410: E/AndroidRuntime(1906): java.lang.NumberFormatException: Invalid int: ""
07-25 14:18:20.410: E/AndroidRuntime(1906): at java.lang.Integer.invalidInt(Integer.java:137)
07-25 14:18:20.410: E/AndroidRuntime(1906): at java.lang.Integer.parseInt(Integer.java:358)
07-25 14:18:20.410: E/AndroidRuntime(1906): at java.lang.Integer.parseInt(Integer.java:331)
07-25 14:18:20.410: E/AndroidRuntime(1906): at com.example.android.BluetoothChat.BluetoothChat$2.handleMessage(BluetoothChat.java:517)
07-25 14:18:20.410: E/AndroidRuntime(1906): at android.os.Handler.dispatchMessage(Handler.java:102)
07-25 14:18:20.410: E/AndroidRuntime(1906): at android.os.Looper.loop(Looper.java:136)
07-25 14:18:20.410: E/AndroidRuntime(1906): at android.app.ActivityThread.main(ActivityThread.java:5141)
07-25 14:18:20.410: E/AndroidRuntime(1906): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 14:18:20.410: E/AndroidRuntime(1906): at java.lang.reflect.Method.invoke(Method.java:515)
07-25 14:18:20.410: E/AndroidRuntime(1906): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
07-25 14:18:20.410: E/AndroidRuntime(1906): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
07-25 14:18:20.410: E/AndroidRuntime(1906): at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
07-25 14:18:20.410: E/AndroidRuntime(1906): at dalvik.system.NativeStart.main(Native Method)
Receive Code
byte[] readBuf = (byte[]) msg.obj;
// construct a string from the valid bytes in the buffer
String readMessage = new String(readBuf, 0, msg.arg1);
mConversationArrayAdapter.add(readMessage);
Bytes in Java are signed so the max range is -128 to +127. If you really just need 1 byte, you can convert it to an integer on the receiving side and add 128 to it to make it in the range of 0-255.
I need to display a PDF file located in my app dir in a webwiev without using Google Docs.
This is my code for the webview:
public void OpenPDF() {
WebView webview = new WebView(this);
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("file://mnt/data/data/com.example.android/files/Docs/test.pdf");;
}
I get a blank webview instead of below code works
public void OpenPDF() {
WebView webview = new WebView(this);
setContentView(webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("file://mnt/data/data/com.example.android/files/Docs/test.html");
}
I tested directly in my web browser with file://mnt/data/data/com.example.android/files/Docs/test.pdf and test.html and it worked for both. I installed a PDF reader.
07-25 17:09:07.967: W/webcore(11347): java.lang.Throwable: EventHub.removeMessages(int what = 107) is not supported before the WebViewCore is set up.
07-25 17:09:07.967: W/webcore(11347): at android.webkit.WebViewCore$EventHub.removeMessages(WebViewCore.java:1683)
07-25 17:09:07.967: W/webcore(11347): at android.webkit.WebViewCore$EventHub.access$7900(WebViewCore.java:926)
07-25 17:09:07.967: W/webcore(11347): at android.webkit.WebViewCore.removeMessages(WebViewCore.java:1795)
07-25 17:09:07.967: W/webcore(11347): at android.webkit.WebView.sendOurVisibleRect(WebView.java:2917)
07-25 17:09:07.967: W/webcore(11347): at android.webkit.ZoomManager.setZoomScale(ZoomManager.java:593)
07-25 17:09:07.967: W/webcore(11347): at android.webkit.ZoomManager.access$1700(ZoomManager.java:49)
07-25 17:09:07.967: W/webcore(11347): at android.webkit.ZoomManager$PostScale.run(ZoomManager.java:984)
07-25 17:09:07.967: W/webcore(11347): at android.os.Handler.handleCallback(Handler.java:605)
07-25 17:09:07.967: W/webcore(11347): at android.os.Handler.dispatchMessage(Handler.java:92)
07-25 17:09:07.967: W/webcore(11347): at android.os.Looper.loop(Looper.java:137)
07-25 17:09:07.967: W/webcore(11347): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-25 17:09:07.967: W/webcore(11347): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 17:09:07.967: W/webcore(11347): at java.lang.reflect.Method.invoke(Method.java:511)
07-25 17:09:07.967: W/webcore(11347): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-25 17:09:07.967: W/webcore(11347): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-25 17:09:07.967: W/webcore(11347): at dalvik.system.NativeStart.main(Native Method)
Any ideas about why only pdf files won't open ?
Their seems to be an answer to your question already in stack overflow at Open Local Html File in Webview - Android
to sum it up : Usage of file:/// before your actual path should solve your problem for everything except .pdf files
Webview does not support PDF in android :(. You need to use google doc according to different sources.
I think you should try with 3 slashes, like that:
webview.loadUrl("file:///mnt/data/data/com.example.android/files/Docs/test.pdf");
The project was working just fine last Thursday, then, some sort of Eclipse bug caused the project properties to get all messed up.
After a splitting and frustrating headache, managed to isolate the issue and fix it....on the emulator, running it on the device gives me the original error messages:
07-25 13:01:08.482: E/AndroidRuntime(4273): FATAL EXCEPTION: main
07-25 13:01:08.482: E/AndroidRuntime(4273): java.lang.ExceptionInInitializerError
07-25 13:01:08.482: E/AndroidRuntime(4273): at java.lang.Class.newInstanceImpl(Native Method)
07-25 13:01:08.482: E/AndroidRuntime(4273): at java.lang.Class.newInstance(Class.java:1319)
07-25 13:01:08.482: E/AndroidRuntime(4273): at android.app.Instrumentation.newActivity(Instrumentation.java:1027)
07-25 13:01:08.482: E/AndroidRuntime(4273): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1885)
07-25 13:01:08.482: E/AndroidRuntime(4273): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
07-25 13:01:08.482: E/AndroidRuntime(4273): at android.app.ActivityThread.access$600(ActivityThread.java:128)
07-25 13:01:08.482: E/AndroidRuntime(4273): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
07-25 13:01:08.482: E/AndroidRuntime(4273): at android.os.Handler.dispatchMessage(Handler.java:99)
07-25 13:01:08.482: E/AndroidRuntime(4273): at android.os.Looper.loop(Looper.java:137)
07-25 13:01:08.482: E/AndroidRuntime(4273): at android.app.ActivityThread.main(ActivityThread.java:4514)
07-25 13:01:08.482: E/AndroidRuntime(4273): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 13:01:08.482: E/AndroidRuntime(4273): at java.lang.reflect.Method.invoke(Method.java:511)
07-25 13:01:08.482: E/AndroidRuntime(4273): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
07-25 13:01:08.482: E/AndroidRuntime(4273): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557)
07-25 13:01:08.482: E/AndroidRuntime(4273): at dalvik.system.NativeStart.main(Native Method)
07-25 13:01:08.482: E/AndroidRuntime(4273): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load game: findLibrary returned null
07-25 13:01:08.482: E/AndroidRuntime(4273): at java.lang.Runtime.loadLibrary(Runtime.java:365)
07-25 13:01:08.482: E/AndroidRuntime(4273): at java.lang.System.loadLibrary(System.java:535)
Already tried at least 12 different ways to fix the "Couldn't load game: findLibrary returned null" error to no avail.
UPDATE: Tried using a 4.0 simulator with the exact same results, so it's definitely tied to android version; however, the project was created and is indeed built for Android 4.0 as the minimum.
Any ideas what might be happening and how to fix it?
Thanks for any replies
Most probably your library is not properly generated. Goto ProjectHome->libs->armeabi->libgame.so . libgame.so file is missing.
This file could be generated when you run create-android-project.bat or equivalent linux file.
which creates empty android project.Try copy paste this file from there.
To build cocos2dx project for Android you should perform two steps.
Build C++ libraries. It can be done with build_native.sh
Build Java Project. It can be done through Eclipse.
Such error will happen if you have missed the first step.
This one I do not understand at all, I am trying to display a custom dialog with no title like this
d.setContentView(R.layout.incident_dialog_layout);
d.requestWindowFeature(Window.FEATURE_NO_TITLE);
doing this gives me an error
07-25 11:56:23.737: E/AndroidRuntime(15680): android.util.AndroidRuntimeException: requestFeature() must be called before adding content
07-25 11:56:23.737: E/AndroidRuntime(15680): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:215)
07-25 11:56:23.737: E/AndroidRuntime(15680): at android.app.Dialog.requestWindowFeature(Dialog.java:1031)
07-25 11:56:23.737: E/AndroidRuntime(15680): at ecm2.android.MainActivity.createNewDialog(MainActivity.java:1121)
07-25 11:56:23.737: E/AndroidRuntime(15680): at ecm2.android.MainActivity$ListViews.onListItemClick(MainActivity.java:614)
07-25 11:56:23.737: E/AndroidRuntime(15680): at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58)
07-25 11:56:23.737: E/AndroidRuntime(15680): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
07-25 11:56:23.737: E/AndroidRuntime(15680): at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
07-25 11:56:23.737: E/AndroidRuntime(15680): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2855)
07-25 11:56:23.737: E/AndroidRuntime(15680): at android.widget.AbsListView$1.run(AbsListView.java:3529)
07-25 11:56:23.737: E/AndroidRuntime(15680): at android.os.Handler.handleCallback(Handler.java:615)
07-25 11:56:23.737: E/AndroidRuntime(15680): at android.os.Handler.dispatchMessage(Handler.java:92)
07-25 11:56:23.737: E/AndroidRuntime(15680): at android.os.Looper.loop(Looper.java:137)
07-25 11:56:23.737: E/AndroidRuntime(15680): at android.app.ActivityThread.main(ActivityThread.java:4745)
07-25 11:56:23.737: E/AndroidRuntime(15680): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 11:56:23.737: E/AndroidRuntime(15680): at java.lang.reflect.Method.invoke(Method.java:511)
07-25 11:56:23.737: E/AndroidRuntime(15680): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-25 11:56:23.737: E/AndroidRuntime(15680): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-25 11:56:23.737: E/AndroidRuntime(15680): at dalvik.system.NativeStart.main(Native Method)
ok that simple enough just change where the request is. So I then change it to this
d.requestWindowFeature(Window.FEATURE_NO_TITLE);
d.setContentView(R.layout.incident_dialog_layout);
dialog works until I start a new activity when I go back and click on the item that creates the dialog I get this error
07-25 11:51:19.182: E/AndroidRuntime(15376): android.util.AndroidRuntimeException: requestFeature() must be called before adding content
07-25 11:51:19.182: E/AndroidRuntime(15376): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:215)
07-25 11:51:19.182: E/AndroidRuntime(15376): at android.app.Dialog.requestWindowFeature(Dialog.java:1031)
07-25 11:51:19.182: E/AndroidRuntime(15376): at ecm2.android.MainActivity.createNewDialog(MainActivity.java:1120)
07-25 11:51:19.182: E/AndroidRuntime(15376): at ecm2.android.MainActivity$ListViews.onListItemClick(MainActivity.java:614)
07-25 11:51:19.182: E/AndroidRuntime(15376): at android.support.v4.app.ListFragment$2.onItemClick(ListFragment.java:58)
07-25 11:51:19.182: E/AndroidRuntime(15376): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
07-25 11:51:19.182: E/AndroidRuntime(15376): at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
07-25 11:51:19.182: E/AndroidRuntime(15376): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2855)
07-25 11:51:19.182: E/AndroidRuntime(15376): at android.widget.AbsListView$1.run(AbsListView.java:3529)
07-25 11:51:19.182: E/AndroidRuntime(15376): at android.os.Handler.handleCallback(Handler.java:615)
07-25 11:51:19.182: E/AndroidRuntime(15376): at android.os.Handler.dispatchMessage(Handler.java:92)
07-25 11:51:19.182: E/AndroidRuntime(15376): at android.os.Looper.loop(Looper.java:137)
07-25 11:51:19.182: E/AndroidRuntime(15376): at android.app.ActivityThread.main(ActivityThread.java:4745)
07-25 11:51:19.182: E/AndroidRuntime(15376): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 11:51:19.182: E/AndroidRuntime(15376): at java.lang.reflect.Method.invoke(Method.java:511)
07-25 11:51:19.182: E/AndroidRuntime(15376): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-25 11:51:19.182: E/AndroidRuntime(15376): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-25 11:51:19.182: E/AndroidRuntime(15376): at dalvik.system.NativeStart.main(Native Method)
so what does it want me to do then since I cant have it after I set the content nore can I have it before I sent the content?????
You are getting that error because the second time you set the dialog layout(this is, when you come back from the second activity), you already have content in your screen.
So, calling requestWindowFeature this second time causes the error.
You'll have to move that statement to onCreate() method, hence only one time is called requestFeature, ensuring no content is added before its call.
Based on the second comment on the question, I would guess that you are calling requestFeature() in the onStart or onResume methods.
requestFeature, as well as setContentView, should called in onCreate(). if you do it anywhere else it will get called again and cause your app to throw an error.
Trying to develop hello world, but getting force close error on emulator. thanks in advance
07-25 12:04:12.308: D/AndroidRuntime(277): Shutting down VM
07-25 12:04:12.308: W/dalvikvm(277): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-25 12:04:12.368: E/AndroidRuntime(277): FATAL EXCEPTION: main
07-25 12:04:12.368: E/AndroidRuntime(277): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.exampe.helloww/com.exampe.helloww.HelloActivity}: java.lang.ClassNotFoundException: com.exampe.helloww.HelloActivity in loader dalvik.system.PathClassLoader[/data/app/com.exampe.helloww-2.apk]
07-25 12:04:12.368: E/AndroidRuntime(277): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
07-25 12:04:12.368: E/AndroidRuntime(277): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-25 12:04:12.368: E/AndroidRuntime(277): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-25 12:04:12.368: E/AndroidRuntime(277): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-25 12:04:12.368: E/AndroidRuntime(277): at android.os.Handler.dispatchMessage(Handler.java:99)
07-25 12:04:12.368: E/AndroidRuntime(277): at android.os.Looper.loop(Looper.java:123)
07-25 12:04:12.368: E/AndroidRuntime(277): at android.app.ActivityThread.main(ActivityThread.java:4627)
07-25 12:04:12.368: E/AndroidRuntime(277): at java.lang.reflect.Method.invokeNative(Native Method)
07-25 12:04:12.368: E/AndroidRuntime(277): at java.lang.reflect.Method.invoke(Method.java:521)
07-25 12:04:12.368: E/AndroidRuntime(277): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-25 12:04:12.368: E/AndroidRuntime(277): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-25 12:04:12.368: E/AndroidRuntime(277): at dalvik.system.NativeStart.main(Native Method)
07-25 12:04:12.368: E/AndroidRuntime(277): Caused by: java.lang.ClassNotFoundException: com.exampe.helloww.HelloActivity in loader dalvik.system.PathClassLoader[/data/app/com.exampe.helloww-2.apk]
07-25 12:04:12.368: E/AndroidRuntime(277): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
07-25 12:04:12.368: E/AndroidRuntime(277): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
07-25 12:04:12.368: E/AndroidRuntime(277): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
07-25 12:04:12.368: E/AndroidRuntime(277): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
07-25 12:04:12.368: E/AndroidRuntime(277): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
07-25 12:04:12.368: E/AndroidRuntime(277): ... 11 more
07-25 12:04:17.158: I/Process(277): Sending signal. PID: 277 SIG: 9
the ClassNotFoundException is usually caused when you try to run your app on lower sdk version than the target sdk
Add your HelloActivity in Manifest file.Due to this your Activity is not found and you are getting ClassNotFoundException as
E/AndroidRuntime(277): Caused by: java.lang.ClassNotFoundException: com.exampe.helloww.HelloActivity