2012-07-18 49 views
0

我已經編寫了這段代碼,嘗試將視頻流式傳輸到我的Android設備。點擊一個圖標後,一個彈出窗口應該與VideoView一起出現。然而,只要我點擊圖片觸發彈出窗口,它就會強制關閉。我使用的URL顯然可以流式傳輸到設備,我從另一個SO問題中獲得了它。這是我班上的代碼。Android:app試圖從URI播放視頻時關閉

video.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      final Dialog dialog = new Dialog(context); 
      dialog.setContentView(R.layout.pop_up); 
      dialog.setTitle("Safe Cracker Overview"); 

      VideoView vv = (VideoView)findViewById(R.id.vv01); 
      MediaController mc = new MediaController(context); 
      mc.setAnchorView(vv); 
      mc.setMediaPlayer(vv); 
      vv.setMediaController(mc); 
      vv.setVideoURI(Uri.parse("http://hermes.sprc.samsung.pl/widget/tmp/testh.3gp")); 
      vv.requestFocus(); 
      vv.start(); 
      Button ok = (Button)findViewById(R.id.but01); 

      ok.setOnClickListener(new View.OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        // TODO Auto-generated method stub 
        dialog.dismiss(); 
       } 
      }); 

      dialog.show(); 
     } 
    }); 

和XML的彈出佈局:

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

    <VideoView 
     android:id="@+id/vv01" 
     android:layout_width="fill_parent" 
     android:layout_height="200dp" 
     android:layout_marginTop="20dp" 
     android:background="#0000" > 
    </VideoView> 

    <Button 
     android:id="@+id/but01" 
     android:layout_width="150dp" 
     android:layout_height="40dp" 
     android:layout_gravity="center" 
     android:layout_marginTop="10dp" 
     android:background="@drawable/green_button" 
     android:text="@string/back" 
     android:textColor="@color/white" 
     android:textSize="16dp" > 
    </Button> 

</LinearLayout> 

有人能看到這裏的問題?由於

+0

請提供堆棧轉儲 – 2012-07-18 14:49:25

回答

1

變化

VideoView vv = (VideoView)findViewById(R.id.vv01);

的refrence與

VideoView vv = (VideoView)dialog .findViewById(R.id.vv01);

Button ok = (Button)findViewById(R.id.but01);Button ok = (Button)dialog .findViewById(R.id.but01);

+0

它不再強制關閉,現在彈出窗口出現,但視頻不會出現在彈出窗口! – Tiffany 2012-07-18 14:58:08

1

你忘了給dialog for VideoView and Button.

VideoView vv = (VideoView)dialog.findViewById(R.id.vv01); 
          ^^^^^^ 
Button ok = (Button)dialog.findViewById(R.id.but01); 
        ^^^^^^