Java Code Examples for org.videolan.libvlc.util.AndroidUtil#isICSOrLater()

The following examples show how to use org.videolan.libvlc.util.AndroidUtil#isICSOrLater() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlaybackService.java    From VCL-Android with Apache License 2.0 6 votes vote down vote up
/**
 * A function to control the Remote Control Client. It is needed for
 * compatibility with devices below Ice Cream Sandwich (4.0).
 *
 * @param state Playback state
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setRemoteControlClientPlaybackState(int state) {
    if (!AndroidUtil.isICSOrLater() || mRemoteControlClient == null)
        return;

    switch (state) {
        case MediaPlayer.Event.Playing:
            mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
            break;
        case MediaPlayer.Event.Paused:
            mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
            break;
        case MediaPlayer.Event.Stopped:
            mRemoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
            break;
    }
}
 
Example 2
Source File: AWindow.java    From libvlc-android-sdk with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void setView(int id, TextureView view) {
    if (!AndroidUtil.isICSOrLater)
        throw new IllegalArgumentException("TextureView not implemented in this android version");
    ensureInitState();
    if (view == null)
        throw new NullPointerException("view is null");
    final SurfaceHelper surfaceHelper = mSurfaceHelpers[id];
    if (surfaceHelper != null)
        surfaceHelper.release();

    mSurfaceHelpers[id] = new SurfaceHelper(id, view);
}
 
Example 3
Source File: AWindow.java    From OTTLivePlayer_vlc with MIT License 5 votes vote down vote up
private void setView(int id, TextureView view) {
    if (!AndroidUtil.isICSOrLater)
        throw new IllegalArgumentException("TextureView not implemented in this android version");
    ensureInitState();
    if (view == null)
        throw new NullPointerException("view is null");
    final SurfaceHelper surfaceHelper = mSurfaceHelpers[id];
    if (surfaceHelper != null)
        surfaceHelper.release();

    mSurfaceHelpers[id] = new SurfaceHelper(id, view);
}
 
Example 4
Source File: AWindow.java    From OTTLivePlayer_vlc with MIT License 5 votes vote down vote up
private void setView(int id, TextureView view) {
    if (!AndroidUtil.isICSOrLater)
        throw new IllegalArgumentException("TextureView not implemented in this android version");
    ensureInitState();
    if (view == null)
        throw new NullPointerException("view is null");
    final SurfaceHelper surfaceHelper = mSurfaceHelpers[id];
    if (surfaceHelper != null)
        surfaceHelper.release();

    mSurfaceHelpers[id] = new SurfaceHelper(id, view);
}
 
Example 5
Source File: AWindow.java    From vlc-example-streamplayer with GNU General Public License v3.0 5 votes vote down vote up
private void setView(int id, TextureView view) {
    if (!AndroidUtil.isICSOrLater)
        throw new IllegalArgumentException("TextureView not implemented in this android version");
    ensureInitState();
    if (view == null)
        throw new NullPointerException("view is null");
    final SurfaceHelper surfaceHelper = mSurfaceHelpers[id];
    if (surfaceHelper != null)
        surfaceHelper.release();

    mSurfaceHelpers[id] = new SurfaceHelper(id, view);
}
 
Example 6
Source File: AWindow.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
private void setView(int id, TextureView view) {
    if (!AndroidUtil.isICSOrLater())
        throw new IllegalArgumentException("TextureView not implemented in this android version");
    ensureInitState();
    if (view == null)
        throw new NullPointerException("view is null");
    final SurfaceHelper surfaceHelper = mSurfaceHelpers[id];
    if (surfaceHelper != null)
        surfaceHelper.release();

    mSurfaceHelpers[id] = new SurfaceHelper(id, view);
}
 
Example 7
Source File: VideoPlayerActivity.java    From VCL-Android with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void startPlayback() {
    /* start playback only when audio service and both surfaces are ready */
    if (mPlaybackStarted || mService == null)
        return;

    mPlaybackStarted = true;

    /* Dispatch ActionBar touch events to the Activity */
    mActionBarView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            onTouchEvent(event);
            return true;
        }
    });

    if (AndroidUtil.isICSOrLater())
        getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(
                new OnSystemUiVisibilityChangeListener() {
                    @Override
                    public void onSystemUiVisibilityChange(int visibility) {
                        if (visibility == mUiVisibility)
                            return;
                        if (visibility == View.SYSTEM_UI_FLAG_VISIBLE && !mShowing && !isFinishing()) {
                            showOverlay();
                        }
                        mUiVisibility = visibility;
                    }
                }
        );

    if (AndroidUtil.isHoneycombOrLater()) {
        if (mOnLayoutChangeListener == null) {
            mOnLayoutChangeListener = new View.OnLayoutChangeListener() {
                private final Runnable mRunnable = new Runnable() {
                    @Override
                    public void run() {
                        changeSurfaceLayout();
                    }
                };
                @Override
                public void onLayoutChange(View v, int left, int top, int right,
                                           int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                    if (left != oldLeft || top != oldTop || right != oldRight || bottom != oldBottom) {
                        /* changeSurfaceLayout need to be called after the layout changed */
                        mHandler.removeCallbacks(mRunnable);
                        mHandler.post(mRunnable);
                    }
                }
            };
        }
        mSurfaceFrame.addOnLayoutChangeListener(mOnLayoutChangeListener);
    }
    changeSurfaceLayout();

    /* Listen for changes to media routes. */
    if (mMediaRouter != null)
        mediaRouterAddCallback(true);

    LibVLC().setOnHardwareAccelerationError(this);
    final IVLCVout vlcVout = mService.getVLCVout();
    vlcVout.detachViews();
    if (mPresentation == null) {
        vlcVout.setVideoView(mSurfaceView);
        if (mSubtitlesSurfaceView.getVisibility() != View.GONE)
            vlcVout.setSubtitlesView(mSubtitlesSurfaceView);
    } else {
        vlcVout.setVideoView(mPresentation.mSurfaceView);
        if (mSubtitlesSurfaceView.getVisibility() != View.GONE)
            vlcVout.setSubtitlesView(mPresentation.mSubtitlesSurfaceView);
    }
    mSurfacesAttached = true;
    vlcVout.addCallback(this);
    vlcVout.attachViews();
    mSurfaceView.setKeepScreenOn(true);

    loadMedia();

    // Add any selected subtitle file from the file picker
    if(mSubtitleSelectedFiles.size() > 0) {
        for(String file : mSubtitleSelectedFiles) {
            Log.i(TAG, "Adding user-selected subtitle " + file);
            mService.addSubtitleTrack(file);
        }
    }

    // Set user playback speed
    mService.setRate(mSettings.getFloat(PreferencesActivity.VIDEO_SPEED, 1));
}
 
Example 8
Source File: VideoPlayerActivity.java    From VCL-Android with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void stopPlayback() {
    if (!mPlaybackStarted)
        return;

    if (mMute)
        mute(false);

    LibVLC().setOnHardwareAccelerationError(null);

    mPlaybackStarted = false;

    mService.removeCallback(this);
    final IVLCVout vlcVout = mService.getVLCVout();
    vlcVout.removeCallback(this);
    if (mSurfacesAttached)
        vlcVout.detachViews();
    mSurfaceView.setKeepScreenOn(false);

    mHandler.removeCallbacksAndMessages(null);

    mDetector.setOnDoubleTapListener(null);

    /* Stop listening for changes to media routes. */
    if (mMediaRouter != null)
        mediaRouterAddCallback(false);

    if (AndroidUtil.isHoneycombOrLater() && mOnLayoutChangeListener != null)
        mSurfaceFrame.removeOnLayoutChangeListener(mOnLayoutChangeListener);

    if (AndroidUtil.isICSOrLater())
        getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(null);

    mActionBarView.setOnTouchListener(null);

    if(mSwitchingView && mService != null) {
        Log.d(TAG, "mLocation = \"" + mUri + "\"");
        mService.showWithoutParse(savedIndexPosition);
        return;
    }

    final boolean isPaused = !mService.isPlaying();
    long time = getTime();
    long length = mService.getLength();
    //remove saved position if in the last 5 seconds
    if (length - time < 5000)
        time = 0;
    else
        time -= 2000; // go back 2 seconds, to compensate loading time
    mService.stop();

    SharedPreferences.Editor editor = mSettings.edit();
    // Save position
    if (mService.isSeekable()) {
        if(MediaDatabase.getInstance().mediaItemExists(mUri)) {
            MediaDatabase.getInstance().updateMedia(
                    mUri,
                    MediaDatabase.INDEX_MEDIA_TIME,
                    time);
        } else {
            // Video file not in media library, store time just for onResume()
            editor.putLong(PreferencesActivity.VIDEO_RESUME_TIME, time);
        }
    }
    if(isPaused)
        Log.d(TAG, "Video paused - saving flag");
    editor.putBoolean(PreferencesActivity.VIDEO_PAUSED, isPaused);

    // Save selected subtitles
    String subtitleList_serialized = null;
    if(mSubtitleSelectedFiles.size() > 0) {
        Log.d(TAG, "Saving selected subtitle files");
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try {
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(mSubtitleSelectedFiles);
            subtitleList_serialized = bos.toString();
        } catch(IOException e) {}
    }
    editor.putString(PreferencesActivity.VIDEO_SUBTITLE_FILES, subtitleList_serialized);

    if (mUri != null)
        editor.putString(PreferencesActivity.VIDEO_LAST, mUri.toString());

    // Save user playback speed and restore normal speed
    editor.putFloat(PreferencesActivity.VIDEO_SPEED, mService.getRate());
    mService.setRate(1.0f);

    Util.commitPreferences(editor);
}