Java Code Examples for org.videolan.libvlc.Media#VideoTrack

The following examples show how to use org.videolan.libvlc.Media#VideoTrack . 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: MediaWrapper.java    From OTTLivePlayer_vlc with MIT License 5 votes vote down vote up
private void init(Media media) {
    mType = TYPE_ALL;

    if (media != null) {
        if (media.isParsed()) {
            mLength = media.getDuration();

            for (int i = 0; i < media.getTrackCount(); ++i) {
                final Media.Track track = media.getTrack(i);
                if (track == null)
                    continue;
                if (track.type == Media.Track.Type.Video) {
                    final Media.VideoTrack videoTrack = (VideoTrack) track;
                    mType = TYPE_VIDEO;
                    mWidth = videoTrack.width;
                    mHeight = videoTrack.height;
                } else if (mType == TYPE_ALL && track.type == Media.Track.Type.Audio){
                    mType = TYPE_AUDIO;
                }
            }
        }
        updateMeta(media);
        if (mType == TYPE_ALL)
            switch (media.getType()) {
                case Media.Type.Directory:
                    mType = TYPE_DIR;
                    break;
                case Media.Type.Playlist:
                    mType = TYPE_PLAYLIST;
                    break;
            }
        mSlaves = media.getSlaves();
    }
    defineType();
}
 
Example 2
Source File: MediaWrapper.java    From OTTLivePlayer_vlc with MIT License 5 votes vote down vote up
private void init(Media media) {
    mType = TYPE_ALL;

    if (media != null) {
        if (media.isParsed()) {
            mLength = media.getDuration();

            for (int i = 0; i < media.getTrackCount(); ++i) {
                final Media.Track track = media.getTrack(i);
                if (track == null)
                    continue;
                if (track.type == Media.Track.Type.Video) {
                    final Media.VideoTrack videoTrack = (VideoTrack) track;
                    mType = TYPE_VIDEO;
                    mWidth = videoTrack.width;
                    mHeight = videoTrack.height;
                } else if (mType == TYPE_ALL && track.type == Media.Track.Type.Audio){
                    mType = TYPE_AUDIO;
                }
            }
        }
        updateMeta(media);
        if (mType == TYPE_ALL)
            switch (media.getType()) {
                case Media.Type.Directory:
                    mType = TYPE_DIR;
                    break;
                case Media.Type.Playlist:
                    mType = TYPE_PLAYLIST;
                    break;
            }
        mSlaves = media.getSlaves();
    }
    defineType();
}
 
Example 3
Source File: MediaInfoAdapter.java    From VCL-Android with Apache License 2.0 5 votes vote down vote up
private void appendVideo(StringBuilder textBuilder, Resources res, Media.VideoTrack track) {
    final double framerate = track.frameRateNum / (double) track.frameRateDen;
    if( track.width != 0 && track.height != 0 )
        textBuilder.append(res.getString(R.string.track_resolution_info, track.width, track.height));
    if( !Double.isNaN(framerate) )
        textBuilder.append(res.getString(R.string.track_framerate_info, framerate));
}
 
Example 4
Source File: MainActivity.java    From libvlc-android-sdk with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void changeMediaPlayerLayout(int displayW, int displayH) {
    /* Change the video placement using the MediaPlayer API */
    switch (CURRENT_SIZE) {
        case SURFACE_BEST_FIT:
            mMediaPlayer.setAspectRatio(null);
            mMediaPlayer.setScale(0);
            break;
        case SURFACE_FIT_SCREEN:
        case SURFACE_FILL: {
            Media.VideoTrack vtrack = mMediaPlayer.getCurrentVideoTrack();
            if (vtrack == null)
                return;
            final boolean videoSwapped = vtrack.orientation == Media.VideoTrack.Orientation.LeftBottom
                    || vtrack.orientation == Media.VideoTrack.Orientation.RightTop;
            if (CURRENT_SIZE == SURFACE_FIT_SCREEN) {
                int videoW = vtrack.width;
                int videoH = vtrack.height;

                if (videoSwapped) {
                    int swap = videoW;
                    videoW = videoH;
                    videoH = swap;
                }
                if (vtrack.sarNum != vtrack.sarDen)
                    videoW = videoW * vtrack.sarNum / vtrack.sarDen;

                float ar = videoW / (float) videoH;
                float dar = displayW / (float) displayH;

                float scale;
                if (dar >= ar)
                    scale = displayW / (float) videoW; /* horizontal */
                else
                    scale = displayH / (float) videoH; /* vertical */
                mMediaPlayer.setScale(scale);
                mMediaPlayer.setAspectRatio(null);
            } else {
                mMediaPlayer.setScale(0);
                mMediaPlayer.setAspectRatio(!videoSwapped ? "" + displayW + ":" + displayH
                        : "" + displayH + ":" + displayW);
            }
            break;
        }
        case SURFACE_16_9:
            mMediaPlayer.setAspectRatio("16:9");
            mMediaPlayer.setScale(0);
            break;
        case SURFACE_4_3:
            mMediaPlayer.setAspectRatio("4:3");
            mMediaPlayer.setScale(0);
            break;
        case SURFACE_ORIGINAL:
            mMediaPlayer.setAspectRatio(null);
            mMediaPlayer.setScale(1);
            break;
    }
}
 
Example 5
Source File: MediaWrapper.java    From VCL-Android with Apache License 2.0 4 votes vote down vote up
private void init(Media media) {
    mType = TYPE_ALL;

    if (media != null) {
        if (media.isParsed()) {
            mLength = media.getDuration();

            for (int i = 0; i < media.getTrackCount(); ++i) {
                final Media.Track track = media.getTrack(i);
                if (track == null)
                    continue;
                if (track.type == Media.Track.Type.Video) {
                    final Media.VideoTrack videoTrack = (VideoTrack) track;
                    mType = TYPE_VIDEO;
                    mWidth = videoTrack.width;
                    mHeight = videoTrack.height;
                } else if (mType == TYPE_ALL && track.type == Media.Track.Type.Audio){
                    mType = TYPE_AUDIO;
                }
            }
        }
        updateMeta(media);
        if (mType == TYPE_ALL && media.getType() == Media.Type.Directory)
            mType = TYPE_DIR;
    }

    if (mType == TYPE_ALL) {
        final int index = mUri.toString().indexOf('?');
        String location;
        if (index == -1)
            location = mUri.toString();
        else
            location = mUri.toString().substring(0, index);
        int dotIndex = location.lastIndexOf(".");
        if (dotIndex != -1) {
            String fileExt = location.substring(dotIndex).toLowerCase(Locale.ENGLISH);
            if( Extensions.VIDEO.contains(fileExt) ) {
                mType = TYPE_VIDEO;
            } else if (Extensions.AUDIO.contains(fileExt)) {
                mType = TYPE_AUDIO;
            } else if (Extensions.SUBTITLES.contains(fileExt)) {
                mType = TYPE_SUBTITLE;
            } else if (Extensions.PLAYLIST.contains(fileExt)) {
                mType = TYPE_PLAYLIST;
            }
        }
    }
}