VideoView在底部绘制黑线

时间:2015-03-18 18:19:01

标签: android android-fragments android-mediaplayer android-videoview

我有问题, 我有一个带片段的ViewPager,我有一个显示视频的VideoFragment。 一切正常,但如果视频加载并开始播放,它会在我认为的视图底部显示一条小黑线。

请参阅屏幕截图以供参考!

http://imgur.com/6j79LIp

这是一些代码,我完全不知道酒吧来自哪里....

我的片段布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/grey_900">

    <com.pr0.pr0.library.CircleProgressBar
        android:id="@+id/progressVideo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/grey_900"
        android:layout_centerInParent="true"
        app:mlpb_show_arrow="true"
        app:mlpb_enable_circle_background="false"
        app:mlpb_arrow_height="5dp"
        app:mlpb_arrow_width="10dp"
        app:mlpb_progress_color="@android:color/holo_red_light"
        android:visibility="visible"/>

    <com.pr0.pr0.view.CustomVideoView
        android:id="@+id/videoView"
        android:layout_width="1px"
        android:layout_height="1px"
        android:layout_centerInParent="true"/>
</RelativeLayout>

我的片段代码:

package com.pr0.pr0.fragment;

import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.MediaController;
import android.widget.RelativeLayout;

import com.pr0.pr0.MainActivity;
import com.pr0.pr0.R;
import com.pr0.pr0.api.Post;
import com.pr0.pr0.library.CircleProgressBar;
import com.pr0.pr0.util.Constants;
import com.pr0.pr0.view.CustomVideoView;

import rx.functions.Action1;

import static rx.android.observables.AndroidObservable.bindActivity;

/**
 * Created by Dominik on 02.03.2015.
 */
public class FullscreenVideoFragment extends Fragment{

    int position;
    CustomVideoView viewVideo;

    /**
     * When creating, retrieve this instance's number from its arguments.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    /**
     * The Fragment's UI is just a simple text view showing its
     * instance number.
     */
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        bindActivity(MainActivity.getActivity(), Constants.api.getPostInformation(Pr0MainPageFragment.itemList.get(position).getId())).subscribe(new Action1<Post>() {
            @Override
            public void call(Post post) {
                Pr0MainPageFragment.itemList.get(position).setPost(post);
            }});
        View v = inflater.inflate(R.layout.fullscreen_video, container, false);
        final CircleProgressBar progressBar = (CircleProgressBar) v.findViewById(R.id.progressVideo);
        progressBar.setColorSchemeResources(android.R.color.holo_red_light);
        viewVideo = (CustomVideoView) v.findViewById(R.id.videoView);
        MediaController ctrl = new MediaController(getActivity());
        ctrl.setVisibility(View.GONE);
        viewVideo.setMediaController(ctrl);

        int padding = getActivity().getResources().getDimensionPixelSize(
                R.dimen.padding_medium);

        //viewVideo.setPadding(padding, padding, padding, padding);
        viewVideo.setVideoURI(Uri.parse("http://img.pr0gramm.com/" + Pr0MainPageFragment.itemList.get(position).getImage()));
        viewVideo.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                viewVideo.seekTo(0);
                viewVideo.start();
            }
        });
        viewVideo.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                progressBar.setVisibility(View.GONE);
                RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
                params.addRule(RelativeLayout.CENTER_IN_PARENT);
                viewVideo.setLayoutParams(params);
                viewVideo.start();
                viewVideo.bringToFront();
            }
        });

        progressBar.bringToFront();
        Log.w("Pr0", "SHOT IT");
        return v;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    public void setPosition(int position){
        this.position = position;
    }
    public static FullscreenVideoFragment newInstace(int position){
        FullscreenVideoFragment fragment = new FullscreenVideoFragment();
        fragment.setPosition(position);
        return fragment;
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (this.isVisible())
        {
            if (!isVisibleToUser)   // If we are becoming invisible, then...
            {
                if(viewVideo != null){
                    viewVideo.pause();
                }
            }

            if (isVisibleToUser)
            {
                if(viewVideo != null){
                    viewVideo.start();
                }
            }

        }

    }
}

1 个答案:

答案 0 :(得分:0)

多米尼克, 我有同样的问题,所以我决定使用另一个视频和黑线消失。我使用了更宽和高的视频......(一个更大的视频本身)