2013-11-20 148 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