Search in sources :

Example 1 with MediaController

use of android.widget.MediaController in project NewPipe by TeamNewPipe.

the class PlayVideoActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_play_video);
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
    //set background arrow style
    getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_arrow_back_white_24dp);
    isLandscape = checkIfLandscape();
    hasSoftKeys = checkIfHasSoftKeys();
    actionBar = getSupportActionBar();
    assert actionBar != null;
    actionBar.setDisplayHomeAsUpEnabled(true);
    Intent intent = getIntent();
    if (mediaController == null) {
        //prevents back button hiding media controller controls (after showing them)
        //instead of exiting video
        //see http://stackoverflow.com/questions/6051825
        //also solves https://github.com/theScrabi/NewPipe/issues/99
        mediaController = new MediaController(this) {

            @Override
            public boolean dispatchKeyEvent(KeyEvent event) {
                int keyCode = event.getKeyCode();
                final boolean uniqueDown = event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_DOWN;
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    if (uniqueDown) {
                        if (isShowing()) {
                            finish();
                        } else {
                            hide();
                        }
                    }
                    return true;
                }
                return super.dispatchKeyEvent(event);
            }
        };
    }
    //convert from seconds to milliseconds
    position = intent.getIntExtra(START_POSITION, 0) * 1000;
    videoView = (VideoView) findViewById(R.id.video_view);
    progressBar = (ProgressBar) findViewById(R.id.play_video_progress_bar);
    try {
        videoView.setMediaController(mediaController);
        videoView.setVideoURI(Uri.parse(intent.getStringExtra(STREAM_URL)));
    } catch (Exception e) {
        e.printStackTrace();
    }
    videoView.requestFocus();
    videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

        @Override
        public void onPrepared(MediaPlayer mp) {
            progressBar.setVisibility(View.GONE);
            videoView.seekTo(position);
            if (position <= 0) {
                videoView.start();
                showUi();
            } else {
                videoView.pause();
            }
        }
    });
    videoUrl = intent.getStringExtra(VIDEO_URL);
    Button button = (Button) findViewById(R.id.content_button);
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (uiIsHidden) {
                showUi();
            } else {
                hideUi();
            }
        }
    });
    decorView = getWindow().getDecorView();
    decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {

        @Override
        public void onSystemUiVisibilityChange(int visibility) {
            if (visibility == View.VISIBLE && uiIsHidden) {
                showUi();
            }
        }
    });
    if (android.os.Build.VERSION.SDK_INT >= 17) {
        decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
    }
    prefs = getPreferences(Context.MODE_PRIVATE);
    if (prefs.getBoolean(PREF_IS_LANDSCAPE, false) && !isLandscape) {
        toggleOrientation();
    }
}
Also used : KeyEvent(android.view.KeyEvent) MediaController(android.widget.MediaController) Button(android.widget.Button) Intent(android.content.Intent) View(android.view.View) VideoView(android.widget.VideoView) MediaPlayer(android.media.MediaPlayer)

Example 2 with MediaController

use of android.widget.MediaController in project android by owncloud.

the class PreviewVideoActivity method onAccountSet.

@Override
protected void onAccountSet(boolean stateWasRecovered) {
    super.onAccountSet(stateWasRecovered);
    if (getAccount() != null) {
        OCFile file = getFile();
        /// Validate handled file  (first image to preview)
        if (file == null) {
            throw new IllegalStateException("Instanced with a NULL OCFile");
        }
        if (!file.isVideo()) {
            throw new IllegalArgumentException("Non-video file passed as argument");
        }
        file = getStorageManager().getFileById(file.getFileId());
        if (file != null) {
            if (file.isDown()) {
                mVideoPlayer.setVideoURI(file.getStorageUri());
            } else {
                // not working yet
                String url;
                try {
                    url = AccountUtils.constructFullURLForAccount(this, getAccount()) + file.getRemotePath();
                    mVideoPlayer.setVideoURI(Uri.parse(url));
                } catch (AccountNotFoundException e) {
                    onError(null, MediaService.OC_MEDIA_ERROR, R.string.media_err_no_account);
                }
            }
            // create and prepare control panel for the user
            mMediaController = new MediaController(this);
            mMediaController.setMediaPlayer(mVideoPlayer);
            mMediaController.setAnchorView(mVideoPlayer);
            mVideoPlayer.setMediaController(mMediaController);
        } else {
            finish();
        }
    } else {
        finish();
    }
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) MediaController(android.widget.MediaController) AccountNotFoundException(com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException)

Example 3 with MediaController

use of android.widget.MediaController in project android_frameworks_base by ResurrectionRemix.

the class VideoDumpActivity method createView.

private View createView() {
    mVideoView = new VideoDumpView(this);
    mVideoView.setMediaController(new MediaController(context));
    LinearLayout mainLayout = new LinearLayout(this);
    mainLayout.addView(mVideoView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
    return mainLayout;
}
Also used : MediaController(android.widget.MediaController) LinearLayout(android.widget.LinearLayout)

Example 4 with MediaController

use of android.widget.MediaController in project android_frameworks_base by ParanoidAndroid.

the class HTML5VideoFullScreen method prepareForFullScreen.

private void prepareForFullScreen() {
    MediaController mc = new FullScreenMediaController(mProxy.getContext(), mLayout);
    mc.setSystemUiVisibility(mLayout.getSystemUiVisibility());
    setMediaController(mc);
    mPlayer.setScreenOnWhilePlaying(true);
    mPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
    prepareDataAndDisplayMode(mProxy);
}
Also used : MediaController(android.widget.MediaController)

Example 5 with MediaController

use of android.widget.MediaController in project WordPress-Android by wordpress-mobile.

the class PhotoChooserPreviewActivity method playVideo.

private void playVideo() {
    final MediaController controls = new MediaController(this);
    mVideoView.setMediaController(controls);
    mVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {

        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            delayedFinish();
            return false;
        }
    });
    mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

        @Override
        public void onPrepared(MediaPlayer mp) {
            controls.show();
            mp.start();
        }
    });
    mVideoView.setVideoURI(mMediaUri);
    mVideoView.requestFocus();
}
Also used : MediaController(android.widget.MediaController) MediaPlayer(android.media.MediaPlayer)

Aggregations

MediaController (android.widget.MediaController)35 MediaPlayer (android.media.MediaPlayer)10 View (android.view.View)7 LinearLayout (android.widget.LinearLayout)6 VideoView (android.widget.VideoView)5 OnPreparedListener (android.media.MediaPlayer.OnPreparedListener)3 OnClickListener (android.view.View.OnClickListener)3 File (java.io.File)3 Intent (android.content.Intent)2 ActionBar (android.support.v7.app.ActionBar)2 KeyEvent (android.view.KeyEvent)2 Button (android.widget.Button)2 OCFile (com.owncloud.android.datamodel.OCFile)2 AccountNotFoundException (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException)2 SharedPreferences (android.content.SharedPreferences)1 Uri (android.net.Uri)1 Nullable (android.support.annotation.Nullable)1 MotionEvent (android.view.MotionEvent)1 InputMethodManager (android.view.inputmethod.InputMethodManager)1 ProgressBar (android.widget.ProgressBar)1