Deno Agüero
Deno Agüero

Reputation: 599

Playing Video in Android over current View

I want to know if it's possible to play a Video over the current View without leaving the Activity. Like an AlertDialog with the blurred effect.

Is there a possibility for this or do you know any libraries?

I didn't find anything for that.

Many thanks in advance.

Upvotes: 0

Views: 70

Answers (2)

Deno Agüero
Deno Agüero

Reputation: 599

I finally solved it with a simple Dialog.

final Dialog dialog = new Dialog(ActQuiz.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.myvideoview);
dialog.show();

WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.copyFrom(dialog.getWindow().getAttributes());
dialog.getWindow().setAttributes(lp);
uriPath= "android.resource://" + getPackageName() + "/" + R.raw.test;
mVideoView.setVideoURI(Uri.parse(uriPath));
mVideoView.start();

Upvotes: 2

H4SN
H4SN

Reputation: 1748

  1. Add the following library to you app build.gradle

    compile 'com.sherazkhilji.videffects:videffects:1.0.2' 
    
  2. In your layout

      <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 In your java class java side:

@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());
}

Upvotes: 0

Related Questions