yixia / VitamioBundle

Vitamio for Android
http://www.vitamio.org/en/
Other
5.27k stars 2.07k forks source link

Cannot Play video in fragment #222

Open shrikantpatnaik opened 9 years ago

shrikantpatnaik commented 9 years ago

Ok, So im trying to build a simple test app to play videos, Im building out a video player fragment, but when the video plays I can only hear the audio. It seems like the elements are there but are invisible for some reason.

Heres my fragment:

package ***

import android.os.Bundle;
import android.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import ***.R;
import io.vov.vitamio.MediaPlayer;
import io.vov.vitamio.widget.MediaController;
import io.vov.vitamio.widget.VideoView;

/**
 * A simple {@link Fragment} subclass.
 *
 */
public class VideoPlayerFragment extends Fragment {
    private String path = "http://www.modrails.com/videos/passenger_nginx.mov";
    private VideoView mVideoView;

    public VideoPlayerFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View rootView = inflater.inflate(R.layout.fragment_video_player, container, false);
        mVideoView = (VideoView) rootView.findViewById(R.id.surface_view);
        if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(getActivity())){
            Log.d("TAG", "Could not load");
        }
        if (path.equals("")) {
            // Tell the user to provide a media file URL/path.
            Toast.makeText(getActivity(), "Please edit VideoViewDemo Activity, and set path" + " variable to your media file URL/path", Toast.LENGTH_LONG).show();
//            return;
        } else {
            /*
             * Alternatively,for streaming media you can use
             * mVideoView.setVideoURI(Uri.parse(URLstring));
             */
            mVideoView.setVideoPath(path);
            mVideoView.setMediaController(new MediaController(getActivity()));
            mVideoView.requestFocus();
            mVideoView.bringToFront();

            mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mediaPlayer) {
                    // optional need Vitamio 4.0
                    mediaPlayer.setPlaybackSpeed(1.0f);
                }
            });
        }
        return rootView;
    }

}

and my layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="#000"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <io.vov.vitamio.widget.CenterLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000"
        android:orientation="vertical" >

        <io.vov.vitamio.widget.VideoView
            android:background="#000"
            android:id="@+id/surface_view"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true" />
    </io.vov.vitamio.widget.CenterLayout>

</LinearLayout>

Here is a screenshot with layout bounds shown of what I see screenshot_2014-11-11-01-13-34

Any hints to what I'm doing wrong?

PS: I just imported vitamio as an android library project to use it

Fiddl3 commented 9 years ago

You set background to SurfaceView (VideoView). SurfaceView draw background on top of Holder. so your video is covered by background

Solution: remove android:background="#000" from xml