On my button click I wrote the following code for playing video from my SDCARD (mp4).
video_view = (VideoView)findViewById(R.id.video_view); video_view.setVideoPath("/sdcard/myvideo.mp4"); video_view.setMediaController(new MediaController(this)); video_view.start();
I can play recorded video from SDCARD in player.
- But when I run it on my application in videoview I can hear only sound.
- Problem : I am not able to see the video.

- 756
- 1
- 8
- 23

- 2,910
- 2
- 22
- 39
13 Answers
I've tried every method above, but none of them could work.
Finally, I tried to call this function, then the video appeared.
video_view.setZOrderOnTop(true);
Hope this also works for you.

- 1,217
- 1
- 10
- 15
-
1I was just having with problem with API 19 Kitkat only, it worked everywhere else. Setting this fixed it. Thanks. – Steven Trigg Feb 24 '14 at 04:04
-
Tried everything under the Sun and this finally worked -- thank ya. – Maurizio Aug 13 '14 at 04:08
-
I think this should be the accepted answer! Thanks a lot! – julianwyz Feb 22 '16 at 22:23
-
3The only issues is that now you can't put anything on top of the video, for example subtitles :( – Miro Mar 30 '16 at 15:27
-
1Any fix on this to put something above the video (subtitle, mute control...)? This is more of a hack than the correct solution! – Ivan May 25 '16 at 18:47
-
@SeaStar video_view.setZOrderOnTop(true); method not found for ScalableVideoView and ScalableVideoView is extends TextureView, Thanks in advance. – Bhavin Patel Sep 13 '16 at 08:39
-
1If you did set a background-color for the VideoView, try removing that backround-color instead of setting the z-order-on-top. – Lensflare May 04 '18 at 10:06
-
I have an overlay I use, so I hide the videoview and then on click event make the videoview visible, but it was not playing. But once I set the zOrderOnTop(true) it was visible. – angryITguy Jan 24 '19 at 06:22
SOLUTION 1:
videoView.setZOrderOnTop(true);
this will set the videoview to the top layer; In other words: block everything under it.
SOLUTION 2:
videoView.setBackgroundColor(Color.TRANSPARENT);
SOLUTION 3:
sometimes this is related about your apptheme; In my case, I changed the apptheme from @style/AppTheme
to @android:style/Theme.NoTitleBar.Fullscreen
fix my problem.

- 8,914
- 14
- 83
- 118

- 171
- 1
- 3
try this :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:id="@+id/view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
it may be help you...

- 1,862
- 2
- 18
- 25
Can you give this a try?
video_view = (VideoView)findViewById(R.id.video_view);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(video_view);
mediaController.setMediaPlayer(video_view); //you probably don't need this
video_view.setVideoPath("/sdcard/myvideo.mp4");
video_view.setMediaController(mediaController);
video_view.start();

- 273
- 1
- 10
-
-
1Ok I'm not sure how this would make a difference but, can you try with `video_view.requestFocus();` just before `video_view.start();` – Pawan Kumar Oct 29 '13 at 09:08
-
I faced the same issue, my video view resized to the expected video resolution but there is nothing on the screen. I tried to use above mentioned solutions but nothing worked.
I tried to set the visibility and that worked, not sure why. This might help someone who come across this post and is facing an issue like me
videoView = (VideoView) findViewById(R.id.viewLiveStream);
videoView.setVisibility(View.VISIBLE);
Here is my XML, not sure why visibility was an issue.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/activity_bg1"
android:orientation="vertical">
<Button
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:id="@+id/btnStreaming"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/start_streaming" />
<TextView
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:id="@+id/txtStreamingUrl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="2" />
<VideoView
android:id="@+id/viewLiveStream"
android:layout_width="640dp"
android:layout_height="480dp"/>
<Button
android:id="@+id/btnPlay"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/play"
android:layout_gravity="center_vertical|center_horizontal"/>
</LinearLayout>
~

- 1,240
- 7
- 18
I had this exact same issue except that I was adding my video view programmatically. I noticed while inspecting the view hierarchy that the parent ViewGroup had it's layer type set to software.
Since the codebase I work on is shared and I didn't notice that the layer type was being setting to software in a subclass of the parent ViewGroup.
So try setting the parent's views layer type to None or Hardware
// Remove this if your parent ViewGroup has this set
//setLayerType(View.LAYER_TYPE_SOFTWARE, null);
// Or set this layer type if the above is not present
setLayerType(View.LAYER_TYPE_NONE, null);

- 81
- 1
- 6
You can do this
video_view = (VideoView)findViewById(R.id.video_view);
video_view.setZOrderMediaOverlay(true);
video_view.setVideoPath("/sdcard/myvideo.mp4");
video_view.setMediaController(new MediaController(this));
video_view.start();
video_view.videoView.setZOrderOnTop(true);
put the setZorderOnTop(true) method after you started the videoView, not before.

- 117
- 1
- 7
My solution was placing the VideoView control at top of the layout and no matter if you set the visibility property.
This work for me on a S6 with Android 6.0

- 9
- 2
<VideoView android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:layout_centerInParent="true"
android:id="@+id/myVideo"/>
public class Videoplay extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_videoplay);
VideoView vidView = (VideoView)findViewById(R.id.myVideo);
MediaController vidControl = new MediaController(this);
String vidAddress = "https://archive.org/download/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512kb.mp4";
Uri vidUri = Uri.parse(vidAddress);
Toast.makeText(Videoplay.this, "Loading Teaser",Toast.LENGTH_LONG).show();
vidView.setVideoURI(vidUri);
vidView.start();
vidControl.setAnchorView(vidView);
vidView.setMediaController(vidControl);
}
Here I am playing the video from one of the links.. It works perfectly for me.
Hope this helps..

- 213
- 1
- 5
- 16
The black screen and audio playing happened with me when I did not release the MediaPlayer object. When you play a video in Activity with media player you have to release it when activity is destroyed. And when you open it again a new instance of media player will be created and use the already released resources.
MediaPlayer.release();

- 146
- 1
- 8
I tried all above answers but did not get success after observing some code, i request focus for my video view. And It is now working on all devices, Hope this will work for some Devs!!
private var mediaController: MediaController? = null
private fun prepareVideo() {
val uri = Uri.fromFile(File(recordedVideoPath))
mediaController = MediaController(this)
mediaController?.setAnchorView(videoView)
videoView.setMediaController(mediaController)
videoView.requestFocus()
videoView.setVideoURI(uri)
videoView.seekTo(2)
videoView.setZOrderOnTop(true)
videoView.setOnPreparedListener {
try {
mediaController?.show(0)
} catch (e: Exception) {
System.out.println("Error in Video")
}
}
videoView.setOnErrorListener { _, _, _ ->
true
}
}

- 339
- 3
- 14
I have same problem but I find out that It was caused by the media file. My video file has 1080x1920 resolution. My device doesn't support height >= 1080 so VideoView has sound only. I use mmpeg to convert supported resolution This is command i use, you can convert it to any code with library:
ffmpeg -i input.mp4 -vf "scale='-1:min(1080,ih)'" output.mp4

- 120
- 1
- 1
- 9