Video is not showing on VideoView but I can hear i

2019-01-11 23:09发布

  • 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.

---- I tried following SO link but still no luck ----

  • link 1
  • link 2

  • Is anybody ever faced this kind of problem ? If yes then how can it solve it ?

11条回答
狗以群分
2楼-- · 2019-01-11 23:15

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(); 
查看更多
Luminary・发光体
3楼-- · 2019-01-11 23:19

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.

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-01-11 23:19

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

查看更多
劫难
5楼-- · 2019-01-11 23:26

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>
~                                                                                           
查看更多
叛逆
6楼-- · 2019-01-11 23:32

I think you use bad mp4 format. Uses Android specific mp4 format!!!

查看更多
淡お忘
7楼-- · 2019-01-11 23:33

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.

查看更多
登录 后发表回答