2016-07-20 10 views
0

RelativeLayoutのVideoViewおよびビデオビューでビデオを開いて再生するコードは以下のとおりです。私はビデオの音を聞くことができますが、ビデオのコンテンツは表示されていません。 ありがとうございます。ビデオビューでSDカードからビデオを再生できない

XMLで
<RelativeLayout 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:background="#9057ac" 
    android:visibility="gone" 
    android:id="@+id/videoContainer"> 
<Button 
    android:id="@+id/CancelRecording" 
    android:layout_width="40dp" 
    android:layout_height="40dp" 
    android:layout_marginRight="10dp" /> 
<VideoView 
    android:id="@+id/VideoPlayer" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="#e3e3e3"/> 
<Button 
    android:id="@+id/UploadButton" 
    android:layout_width="40dp" 
    android:layout_height="40dp" 
    android:layout_marginRight="10dp" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true"/> 
</RelativeLayout> 


public class CameraActivity extends Activity{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.third_activity_viewpager); 
    private RelativeLayout videoContainer; 
    videoContainer = (RelativeLayout) findViewById(R.id.videoContainer); 
    videoContainer.setVisibility(View.VISIBLE); 
    String video = file.toString(); 
        videoView.setVideoURI(Uri.parse(video)); 
        videoView.start(); 
//i checked the *file* path is correct no need to worry about Path. 
} 

答えて

0
  Change video video view to textureview and use it 

あなたactvityで

  <RelativeLayout 
     android:id="@+id/preview_video_parent" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_marginTop="62dp"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:weightSum="1"> 

      <TextureView 
       android:id="@+id/preview_video" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="0.5" /> 

      <TextureView 
       android:id="@+id/preview_video_2" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_weight="0.5" /> 
     </LinearLayout> 

     <ImageView 
      android:id="@+id/previre_play" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:scaleType="center" 
      android:src="@drawable/icn_play_big" /> 
    </RelativeLayout> 

implements TextureView.SurfaceTextureListener  , OnClickListener, OnCompletionListener 

     private TextureView surfaceView; 

private ImageView imagePlay; 

     surfaceView = (TextureView) findViewById(R.id.preview_video_2); 

     surfaceView.setSurfaceTextureListener(this); 
       surfaceView.setOnClickListener(this); 

       path = getIntent().getStringExtra("your path"); 

     mediaPlayer = new MediaPlayer(); 
       mediaPlayer.setOnCompletionListener(this); 
      } 

      @Override 
      protected void onStop() { 
       if (mediaPlayer.isPlaying()) { 
        mediaPlayer.pause(); 
        imagePlay.setVisibility(View.GONE); 
       } 
       super.onStop(); 
      } 

      private void prepare(Surface surface) { 
       try { 
        mediaPlayer.reset(); 
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
        mediaPlayer.setDataSource(path); 
        mediaPlayer.setSurface(surface); 
        mediaPlayer.setLooping(true); 
        mediaPlayer.prepare(); 
        mediaPlayer.seekTo(0); 
       } catch (Exception e) { 
       } 
      } 

      @Override 
      public void onSurfaceTextureAvailable(SurfaceTexture arg0, int arg1, 
                int arg2) { 
       prepare(new Surface(arg0)); 
      } 

      @Override 
      public boolean onSurfaceTextureDestroyed(SurfaceTexture arg0) { 
       return false; 
      } 

      @Override 
      public void onSurfaceTextureSizeChanged(SurfaceTexture arg0, int arg1, 
                int arg2) { 

      } 

      @Override 
      public void onSurfaceTextureUpdated(SurfaceTexture arg0) { 

      } 
+0

だけでなく、私は多くのポイントを持っていけないので、あなたがスコアを与える傾けます。 私はあなたに-100点を与えることをここに書く必要があります。この解決策は、これが単一行であったことです。 videoView.setZOrderOnTop(true); 私はこれを実装する前に追加する必要があります videoView.setOnPreparedListener thats it ... !!! –

+0

あなたはこのような行動をしても体を助けません。私はあなたの助けのために私の全体のコードをここに入れました。これは完全に間違っているわけではありません。 –

+0

Android開発では新しいものを見て、コードを貼り付けてしまったので、完全に間違ってコードを書き込んでしまったので、私はすべて役に立たないと思っていました。これは私がQuerryをもっと魅力的に検索したときに私を怒らせました。私は解決策を見つけました。あなたのコードはちょっと混乱していて、やっていることを完全に変えました! –

関連する問題