2017-04-16 28 views
0

我想知道是否可以在不離開活動的情況下通過當前視圖播放視頻。就像AlertDialog的模糊效果一樣。在Android中通過當前播放視頻查看

有沒有這種可能性或你知道任何圖書館?

我沒有找到任何東西。

非常感謝提前。

回答

2

我終於用一個簡單的Dialog解決了它。

0
  1. 以下庫的build.gradle

    compile 'com.sherazkhilji.videffects:videffects:1.0.2' 
    
  2. 應用添加到您在您的佈局

    <RelativeLayout 
        xmlns:android="http://schemas.android.com/apk/res/android" 
        xmlns:app="http://schemas.android.com/apk/res-auto" 
        xmlns:tools="http://schemas.android.com/tools" 
        android:id="@+id/activity_main" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent"> 
    
    <com.sherazkhilji.videffects.view.VideoSurfaceView 
        android:id="@+id/mVideoSurfaceView" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" /> 
    
    <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:background="#a0000000"> 
    
        //your layout goes here 
    
        </LinearLayout> 
    
    </RelativeLayout> 
    

3在Java類Java方面:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    playVdo(); 
} 

@Override 
protected void onResume() { 
    super.onResume(); 
    mVideoView.onResume(); 
} 

@Override 
protected void onPause() { 
    super.onPause(); 
    mVideoView.onPause(); 
} 

private MediaPlayer mMediaPlayer; 
private Resources mResources; 
private VideoSurfaceView mVideoView; 

private void playVdo() { 
    mResources = getResources(); 
    mMediaPlayer = new MediaPlayer(); 
    mMediaPlayer.setScreenOnWhilePlaying(true); 
    mMediaPlayer.setVolume(0, 0); 
    try { 
     AssetFileDescriptor afd = getAssets().openFd("login_vdo.mp4"); 
     mMediaPlayer.setDataSource(afd.getFileDescriptor(), 
       afd.getStartOffset(), afd.getLength()); 
    } catch (Exception e) { 
     Log.e("mMediaPlayer", e.getMessage(), e); 
    } 
    mVideoView = (VideoSurfaceView) findViewById(R.id.mVideoSurfaceView); 
    mVideoView.init(mMediaPlayer, 
      new DocumentaryEffect()); 
} 
相關問題