【问题标题】:VideoView on the Nexus 10Nexus 10 上的 VideoView
【发布时间】:2014-02-11 18:05:35
【问题描述】:

我在 FragmentDialog 内使用 VideoView(以允许我将其用作嵌套/全屏播放器)。

它在我所有的设备 (xoom/n4) 上都运行良好,但在我的 Nexus10 上,视频显示没有显示(黑色矩形),但我能听到声音。 如果我不使用片段,则播放工作正常,所以这不是编解码器问题。

VideoView 被某些东西“隐藏”了。

你们中有人知道如何解决它吗?

非常感谢!!

(PS:播放开始时占位符隐藏)

我的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"    
    android:background="#FF0000"
    android:id="@+id/fragmentDialogLayout" 
>   

    <FrameLayout android:id="@+id/placeholder" 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" 
        android:background="#00FF00"
        android:layout_gravity="center"
        android:layout_centerInParent="true"
    />

    <VideoView android:id="@+id/VideoView"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:layout_centerInParent="true"        
    />

    <ProgressBar android:id="@+id/ProgressBar"      
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
    />


</RelativeLayout>

java的一些重要部分:

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle b)
{
    View view = inflater.inflate(R.layout.VideoLayout, container);

    initDialog();
    initWindow();
    return view;
}

public void onActivityCreated(Bundle savedInstanceState)
{
    super.onActivityCreated(savedInstanceState);
    getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(
        Color.TRANSPARENT));
}

void initDialog()
{
    setCancelable(false);
    getDialog().setCanceledOnTouchOutside(false);       
    getDialog().setOnKeyListener(this);
}

void initWindow()
{
    window = getDialog().getWindow();
    window.setGravity(Gravity.TOP|Gravity.LEFT);
    window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
        WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
    //window.setBackgroundDrawable(new ColorDrawable(Color.BLACK));

    setPosition(0, 0);
    setSize(640, 480);
}
public void setPosition(int x, int y)
{
    WindowManager.LayoutParams attr = window.getAttributes();

    attr.x = x; 
    attr.y = y;

    updateAttributes(attr);     
}

public void setSize(int width, int height)
{
    WindowManager.LayoutParams attr = window.getAttributes();

    attr.width = width;
    attr.height = height;

    updateAttributes(attr);
}

public void updateAttributes(final WindowManager.LayoutParams attr)
{
    getActivity().runOnUiThread(new Runnable()
    {
        public void run()
        {
            window.setAttributes(attr);
        }
    });
}

//@see android.media.MediaPlayer.OnPreparedListener
public void onPrepared(MediaPlayer mp)
{
    View placeholder = (View)getView().findViewById(R.id.placeholder);
    placeholder.setVisibility(View.GONE);

    videoPlayer.setBackgroundColor(Color.TRANSPARENT);

    mediaPlayer = mp;
    mediaPlayer.setLooping(playbackLoop);

    progressBar.setVisibility(View.INVISIBLE);

    mp.setOnBufferingUpdateListener(this);  
    mp.setOnInfoListener(this);     
}

void preparePlayback()
{
    progressBar.setVisibility(View.VISIBLE);

    videoPlayer.setKeepScreenOn(true);
    videoPlayer.requestFocus();
}

【问题讨论】:

  • 我猜that 网站会有所帮助..告诉我您的问题是否已解决?
  • 占位符隐藏在 onPrepare 中。即使没有占位符,它仍然没有显示。

标签: android android-videoview android-dialogfragment


【解决方案1】:

您是否在 Google 上搜索过这个问题?

看看:

VideoView is not displayed on a Fragment

  • getActivity() 代替 getApplicationContext()
  • 启用硬件加速
  • 显示更多代码 ;)

【讨论】:

  • 嗨,是的,我已经尝试过了。 (我用一点 java 编辑了这个问题)
猜你喜欢
  • 1970-01-01
  • 2013-02-19
  • 2012-12-12
  • 2013-08-30
  • 2016-10-21
  • 1970-01-01
  • 1970-01-01
  • 2013-06-26
  • 1970-01-01
相关资源
最近更新 更多