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:33

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

查看更多
仙女界的扛把子
3楼-- · 2019-01-11 23:34

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.

查看更多
冷血范
4楼-- · 2019-01-11 23:35
<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..

查看更多
【Aperson】
5楼-- · 2019-01-11 23:35

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);
查看更多
ら.Afraid
6楼-- · 2019-01-11 23:36

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();

查看更多
登录 后发表回答