i dont understand: in the previous forum i have put code examples for that and (if i can remember) everything was ok, though not simple because the question was not only about video but for full screen video, which means using surfaceView. Anyway, in the most simple case, you have 1) to use mediaPlayer from Android and add a videoView 2) give it the path to your video, which can be some url on line, some file on your sd card or some file in your app: code for doing that depends of your choice 3) add if you want some mediaController.
more details here: https://developer.android.com/reference/android/widget/VideoView
Try doing that and if you have any problem put your code: without it is difficult to help.
Yes, @akenaton is right … there is code that works. I did it just to learn how … I will post later the complete code I eventually got working.
EDIT: Here’s the code … it is messy, and is still (for me) experimental, but it runs. There are things unrelated to the video itself like getting the SD card details, and drawing a rect in Draw() … for my future use …and the SurfaceHolder.setType method is showing as deprecated. But it does play an mp4 video so hopefully will get you going?!
i got a look to the post; everything is ok and i am sure that it works; yet, as i have told to you, this code is for using videos on the sdcard and it uses surface view (you can also do the same with textureview); if you want to use videos that are in your data or assets folder you have to change the code (that is not very complicated) and if you want only the videoview the code could be more simple.
Hi, I tried the code and got a weird error about a theme ?
See below.
Any thoughts?
Thanks,
Phil
FATAL EXCEPTION: main
Process: processing.test.androidvideo_v01, PID: 9266
java.lang.RuntimeException: Unable to start activity ComponentInfo{processing.test.androidvideo_v01/processing.test.androidvideo_v01.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:920)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:715)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:354)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:293)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:149)
at processing.test.androidvideo_v01.MainActivity.onCreate(MainActivity.java:21)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
... 10 more
I fixed that issue by adding this line to my manifest.xml
android:theme="@style/Theme.AppCompat.Light"
I have one mp4 file in my data folder.
But now I’m getting a different error…
FATAL EXCEPTION: GLThread 538
Process: processing.test.androidvideo_v01, PID: 12079
java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
at processing.test.androidvideo_v01.AndroidVideo_v01.setup(AndroidVideo_v01.java:69)
at processing.core.PApplet.handleDraw(PApplet.java:1846)
at processing.opengl.PSurfaceGLES$RendererGLES.onDrawFrame(PSurfaceGLES.java:264)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1522)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1239)
sorry! i have read the first post and answered without reading next one! - As for the second error it s difficult to help without more details: yet it claims about an arrayoutof bounds and i guess that this is caused by your code about SD cards; is your println() ok???
that is exactly what i guessed: your SDCards array returns only the primary card and it is not so easy to get the second one; try the code without these lines about SDcards and tell me what happens…
@philspitler===
these functions are called automatically and according to the fragment lifecycle one after the other but not all in any case: that depends of the os, its needs for other app and what your app is doing: onDestroy() for example is called if the os needs to get free of your app because another one has been launched. Anyway it s quite always a good idea to write all of them, especially when you app uses resources which the user could want to use: video, sound, cam, mic (and generally speaking any mediaplayer stuff). As for the code, you are right, it is redundant to release the player three times!
As for the other point, do you want that the whole screen becomes (on tap) black or only space occupied by the video?