2017-07-05 30 views
1

如何在帶對象的對話框中設置videoView。如何在對話框中設置videoView android

我儘量不工作(不顯示視頻)

AlertDialog.Builder builder = new AlertDialog.Builder(context); 
    final AlertDialog dialog = builder.create(); 
    final VideoView video_player_view = (VideoView)dialog.findViewById(R.id.videos); 
    LayoutInflater inflater = ((HomeActivity)context).getLayoutInflater(); 
    View dialogLayout = inflater.inflate(R.layout.fragment_fong, null); 

    dialog.setView(dialogLayout); 
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    dialog.show(); 

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
    RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
lp.copyFrom(dialog.getWindow().getAttributes()); 
    dialog.getWindow().setAttributes(lp); 

    Uri uri = Uri.parse("http://file2.video9.in/english/movie/2014/x-men-_days_of_future_past/X-Men-%20Days%20of%20Future%20Past%20Trailer%20-%20[Webmusic.IN].3gp"); 
    video_player_view.setVideoURI(uri); 
    video_player_view.start(); 

和fragment_fong.xml(videoView)

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin"> 

    <VideoView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/videos" /> 
</RelativeLayout> 

如何設置,謝謝你幫

+0

更改:最終VideoView video_player_view =(VideoView)dialog.findViewById(R.id.videos);到 final VideoView video_player_view =(VideoView)dialogLayout.findViewById(R.id.videos); – akhilesh0707

+0

@ akhilesh0707它仍然是錯誤 –

+0

做videoView顯示,但視頻不播放? –

回答

2

視頻不玩

LayoutInflater inflater = ((HomeActivity) context).getLayoutInflater(); 
     View dialogLayout = inflater.inflate(R.layout.fragment_fong, null); 
     AlertDialog.Builder builder = new AlertDialog.Builder(context); 

     final AlertDialog dialog = builder.create(); 
     dialog.setView(dialogLayout); 
     dialog.show(); 
     // dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
     final VideoView video_player_view = (VideoView) dialog.findViewById(R.id.videos); 

     WindowManager.LayoutParams lp = new WindowManager.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
     lp.copyFrom(dialog.getWindow().getAttributes()); 
     dialog.getWindow().setAttributes(lp); 

     Uri uri = Uri.parse("http://file2.video9.in/english/movie/2014/x-men-_days_of_future_past/X-Men-%20Days%20of%20Future%20Past%20Trailer%20-%20[Webmusic.IN].3gp"); 
     video_player_view.setVideoURI(uri); 
     video_player_view.start(); 
+0

我有一些問題,現在視頻顯示和播放,但視頻像背景對話框(純色)改變顏色。如何解決它 –

相關問題