2013-11-20 75 views
0

我在安卓視頻播放中遇到問題。從服務器製作視頻並設置爲videoview,但視頻在後臺播放中無法看到視頻,請參閱我的代碼我嘗試過的內容。如何設置android視頻寬度和高度

XML文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 
<VideoView 
         android:id="@+id/eventDetailsPage_videosView" 
         android:layout_width="160dp" 
         android:layout_height="100dp" 
         android:layout_marginBottom="16dp" 
         android:layout_marginLeft="16dp" 
         android:layout_marginTop="16dp" 

         android:background="@drawable/ic_eventvideo_image" /> 

</LinearLayout> 

的Java類

Uri uri=Uri.parse(mEventDetailsUtil1.getAttachmentsUrls().get(0).getAttach_url()); 

      VideoView mVideosView = (VideoView) findViewById(R.id.eventDetailsPage_videosView); 
      MediaController mc = new MediaController(this); 

      mc.setAnchorView(mVideosView); 
      mc.setMediaPlayer(mVideosView); 
      mVideosView.setMediaController(mc); 
      mVideosView.setVideoURI(uri); 
      mVideosView.requestFocus(); 
       mVideosView.start(); 

視頻是打開活動時玩,但我不想這樣,我需要當我在VideoView點擊我需要打開視頻全屏。

回答

1

試試這個:

VideoView mVideoview; 
mVideoview = (VideoView) findViewById(R.id.VideoView); 
mPlayServer = (Button) findViewById(R.id.mServerbutton); 

mPlayServer.setOnClickListener(new OnClickListener() { 

     public void onClick(View v) { 
      playVideo(SERVER_VIDEO_URL); 
     } 

    }); 

      private void playVideo(SERVER_VIDEO_URL) 
      try { 
    // Start the MediaController 
      MediaController mediacontroller = new MediaController(mContext); 
      mediacontroller.setAnchorView(mVideoview); 
      // Get the URL from String VideoURL 
      mVideo = Uri.parse(SERVER_VIDEO_URL); 
      mVideoview.setMediaController(mediacontroller); 
      mVideoview.setVideoURI(mVideo); 

     } catch (Exception e) { 
      Log.e("Error", e.getMessage()); 
      e.printStackTrace(); 

     } 

     mVideoview.requestFocus(); 
     mVideoview.setOnPreparedListener(new OnPreparedListener() { 
      // Close the progress bar and play the video 
      public void onPrepared(MediaPlayer mp) { 

       mVideoview.start(); 

      } 
     }); 

     mVideoview.setOnCompletionListener(new OnCompletionListener() { 
      // Called when video is completed 
      public void onCompletion(MediaPlayer mp) { 

      } 
     }); 
        } 

要顯示在高度和寬度作爲填充母新的XML文件的全屏使用影片觀看和意圖開始新的活動。

希望這會有所幫助。

+0

謝謝@Siddharth維亞斯我會嘗試 – venu

+0

@Ydder這可能會有所幫助http://www.edumobile.org/android/android-beginner-tutorials/how-to-play-a-video-file/ –

1

Android不支持調整視頻大小,您可能需要查看可以使用的第三方庫。默認情況下,android沒有這個。在對視頻播放器應用控件時,我遇到了同樣的問題。

+0

是它打開新的屏幕賴特 – venu