Android Texture VideoView having a variety of scale types like the scale types of ImageView such as fitCenter, centerCrop, centerTopCrop and more

Overview

Android-ScalableVideoView

Android Arsenal License Download

Looking for the extra scale types of ImageView? Check out ScalableImageView.

Android Texture VideoView having a variety of scale types like the scale types of ImageView.

Sample

Sample

Release Note

[Release Note] (https://github.com/yqritc/Android-ScalableVideoView/releases)

Gradle

repositories {
    jcenter()
}

dependencies {
    compile 'com.yqritc:android-scalablevideoview:1.0.4'
}

Support Scale Types

Scale to fit

  • fitXY
  • fitStart
  • fitCenter
  • fitEnd

No Scale

  • leftTop
  • leftCenter
  • leftBottom
  • centerTop
  • center
  • centerBottom
  • rightTop
  • rightCenter
  • rightBottom

Crop

  • leftTopCrop
  • leftCenterCrop
  • leftBottomCrop
  • centerTopCrop
  • centerCrop
  • centerBottomCrop
  • rightTopCrop
  • rightCenterCrop
  • rightBottomCrop

Scale Inside

  • startInside
  • centerInside
  • endInside

Usage

Set scale type in layout file

<com.yqritc.scalablevideoview.ScalableVideoView
  android:id="@+id/video_view"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_marginBottom="100dp"
  app:scalableType="fitCenter"/>

Please refere the following xml for the list of scalableType you can set.
attrs.xml

Sample usage in source code

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  
  mVideoView = (ScalableVideoView) findViewById(R.id.video_view);
  try {
    mVideoView.setRawData(R.raw.landscape_sample);
  } catch (IOException ioe) {
    //handle error
  }
}

@Override
public void onClick(View v) {
  switch (v.getId()) {
    case R.id.btn_start:
        mVideoView.start();
        break;
    case R.id.btn_update_scale:
        mVideoView.setScalableType(ScalableType.CENTER_TOP_CROP);
        mVideoView.invalidate();
        break;
      default:
        break;
  }
}

ScalableVideoView is extending TextureView to play video by using MediaPlayer.
Basic functionalities are defined in this class to play and scale video.
If you need to control more, extend this class and define your custom video view.

License

Copyright 2015 yqritc

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • Problem with ScalableVideoView in Recycler view

    Problem with ScalableVideoView in Recycler view

    I noticed problem while checking out demo of your library on Google Play Store. I was using Nexus 5X with Android 6.0 on board. The problem I noticed happened with video list - RecyclerView in this case. While scrolling up and down for some row display black view instead of video view. Please refer to attached screenshots.

    screenshot_20151108-215532 screenshot_20151108-215540

    opened by depodefi 5
  • Android Studio Compile Error

    Android Studio Compile Error

    Hi,

    Android Studio is not going to compile and run, any suggestions?

    Warning:Dependency org.apache.httpcomponents:httpclient:4.5.1 is ignored for debug as it may be conflicting with the internal version provided by Android. In case of problem, please repackage it with jarjar to change the class packages Warning:Dependency org.apache.httpcomponents:httpclient:4.5.1 is ignored for release as it may be conflicting with the internal version provided by Android. In case of problem, please repackage it with jarjar to change the class packages

    Error:Execution failed for task ':sample:transformClassesWithDexForDebug'.

    com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2

    opened by simongiesen 3
  • Why aren't you using the Size class in android.util package

    Why aren't you using the Size class in android.util package

    The class Size already exists in the Android package android.util.Size

    http://developer.android.com/reference/android/util/Size.html

    I'll try do make a PR if you're not planning to do it and agree ;)

    opened by ChristopheCVB 2
  • Programitically set width and height of particular video to videoView

    Programitically set width and height of particular video to videoView

    Right now in sample project FrameLayout height is 300dp. If I changed to match_parent / wrap_content the video is not playing. So, height & width of the video should be set to video view. Can you add this in your library itself or please let me know how can I do my self !

    opened by anvesh523 2
  • Added ability to set MediaPlayer.OnErrorListener in prepare() and prepareAsync()

    Added ability to set MediaPlayer.OnErrorListener in prepare() and prepareAsync()

    Now you can set OnErrorListener in prepare() and prepareAsync() methods:

    mVideoView.prepareAsync(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            Log.v("mVideoView", "onPrepared");
        }
    }, new MediaPlayer.OnErrorListener() {
        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            Log.e("mVideoView", "Error: " + waht);
            return false;
        }
    });
    

    Basically added 2 new methods:

    public void prepare(@Nullable MediaPlayer.OnPreparedListener listener, @Nullable MediaPlayer.OnErrorListener eListener)
                throws IOException, IllegalStateException
    
    public void prepareAsync(@Nullable MediaPlayer.OnPreparedListener listener, @Nullable MediaPlayer.OnErrorListener eListener)
                throws IllegalStateException
    
    opened by oleynikd 2
  • hello,I have a question,How to control only one instance is playing

    hello,I have a question,How to control only one instance is playing

    ScalableVideoView in viewpager , when viewpager selected , i release the last but it's still playing , the next one can't play anything ,how to release the last ScalableVideoView?

    i set ScalableVideoView.release but it seems dosen't work

    opened by fansangg 1
  • is it possible to playing the specific frame?

    is it possible to playing the specific frame?

    I wan to create a function to playing the video as GIFs. For example, the length of the video is 2 second (fixed). The frame rate is 12/s. Total frame is 24. When i clicked the button, the scalableVideoView will show no.10 frame.

    opened by waikchiu5 1
  • fix IllegalStateException in onDetachedFromWindow

    fix IllegalStateException in onDetachedFromWindow

    fix IllegalStateException when release called release before onDetachedFromWindow.

    Details: In my HM note(China Xiaomi Inc), I use ScalableVideoView in fragment, I init ScalableVideoView in onViewCreated method, and when I destroy this fragment and recreate it again, the video could not be played, when I call ScalableVideoView.release() in onDestroyView method, the video could be played again in the condition above, but my app will crash with IllegalStateException, when the fragment is destroyed again.

    I think set mMediaPlayer = null; in release() method could be solve this problem, and it does in my project (I introduce this repo's source into my project and set mMediaPlayer = null;, and the crash goes off).

    opened by Piasy 1
  • video has gray border around it in Android 6.

    video has gray border around it in Android 6.

    Hi,

    It's a great library :). I recently used it to scale my video. It works perfectly in Android5. However, in android 6, my video always has a gray border. Here's my code:

    <com.yqritc.scalablevideoview.ScalableVideoView android:id="@+id/video_view" android:layout_width="200dp" android:layout_height="100dp" android:layout_centerInParent="true" app:scalableType="centerCrop" />

    Since my parent background is white, the gray border of the video looks ugly right now. Could you please help me with that ? Thanks. :)

    opened by shumin0809 1
  • hello,I have a question,How to control only one instance is playing

    hello,I have a question,How to control only one instance is playing

    ScalableVideoView in viewpager , when viewpager selected , i release the last ont but it's still playing , the next one can't play anything ,how to release the last one?

    i set ScalableVideoView.release but it seems don's work

    opened by fansangg 0
  • Playing video stored in device storage

    Playing video stored in device storage

    I want to play video which is stored in external storage.I tried using below code but its not working.

    contentVideoView.setDataSource(context,Uri.parse(Environment.getExternalStorageDirectory() + "/demo.mp4"));
    
    contentVideoView.start();
    
    contentVideoView.setLooping(true);
    

    Also I tried

    contentVideoView.setDataSource(Environment.getExternalStorageDirectory() + "/demo.mp4");
    contentVideoView.start();
    contentVideoView.setLooping(true);
    

    but it also didn't worked.

    opened by bkjbkjbnkj687698698 0
  • Distribute by jitpack

    Distribute by jitpack

    Motivation

    jcenter which is the repository for this app was shutdown at May 1st 2021 https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/

    What changes in this PR

    • Use latest Android Gradle Plugin
    • Update support libraries
    • Use JitPack maven repository
    • Update version code to v1.0.5

    You can use this version of library without merging 😉

      allprojects {
        repositories {
    +      maven { url 'https://jitpack.io' }
        }
      }
    
      dependencies {
    +   implementation 'com.github.tomorrowkey:Android-ScalableVideoView:1.0.5'
      }
    

    https://jitpack.io/#tomorrowkey/Android-ScalableVideoView

    opened by tomorrowkey 0
  • Forked and Ported to JitPack!

    Forked and Ported to JitPack!

    As JCenter has been deprecated for some time now I’ve gone ahead to fork and republish this library on JitPack. If anyone needs it, you can find it at: https://github.com/thang2162/Android-ScalableVideoView

    opened by thang2162 1
  • Problem in optimization scalable

    Problem in optimization scalable

    I am using React Native and React Native video for creating streaming TV app. I monitored TV app in resize mode contain and resize mode cover, when I use cover CPU work increase 40%
    first image with resize mode contain photo_2022-04-25_17-38-01

    opened by samandarkuchkarov 0
  • Getting ANR on Android because of Video view

    Getting ANR on Android because of Video view

    Hey there! thanks for the awesome library, i just currently have one issue. I am getting a ANR for a lot of users with stack trace mentioned below

    main (unknown): tid=1 systid=6019
           at android.media.MediaHTTPConnection.disconnect(MediaHTTPConnection.java:193)
           at android.media.IMediaHTTPConnection$Stub.onTransact(IMediaHTTPConnection.java:132)
           at android.os.Binder.execTransactInternal(Binder.java:1166)
           at android.os.Binder.execTransact(Binder.java:1130)
           at android.media.MediaPlayer._reset(MediaPlayer.java)
           at android.media.MediaPlayer.reset(MediaPlayer.java:2252)
           at com.yqritc.scalablevideoview.ScalableVideoView.reset(ScalableVideoView.java:248)
           at com.yqritc.scalablevideoview.ScalableVideoView.release(ScalableVideoView.java:252)
           at com.brentvatne.react.ReactVideoView.cleanupMediaPlayerResources(ReactVideoView.java:242)
           at com.brentvatne.react.ReactVideoViewManager.onDropViewInstance(ReactVideoViewManager.java:56)
           at com.brentvatne.react.ReactVideoViewManager.onDropViewInstance(ReactVideoViewManager.java:17)
           at com.facebook.react.uimanager.NativeViewHierarchyManager.dropView(NativeViewHierarchyManager.java:635)
           at com.facebook.react.uimanager.NativeViewHierarchyManager.dropView(NativeViewHierarchyManager.java:646)
           at com.facebook.react.uimanager.NativeViewHierarchyManager.dropView(NativeViewHierarchyManager.java:646)
           at com.facebook.react.uimanager.NativeViewHierarchyManager.dropView(NativeViewHierarchyManager.java:646)
           at com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren(NativeViewHierarchyManager.java:499)
           at com.facebook.react.uimanager.UIViewOperationQueue$ManageChildrenOperation.execute(UIViewOperationQueue.java:217)
           at com.facebook.react.uimanager.UIViewOperationQueue$1.run(UIViewOperationQueue.java:915)
           at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:1026)
           at com.facebook.react.uimanager.UIViewOperationQueue.access$2600(UIViewOperationQueue.java:47)
           at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:1086)
           at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:29)
           at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:175)
           at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:85)
           at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1138)
           at android.view.Choreographer.doCallbacks(Choreographer.java:962)
           at android.view.Choreographer.doFrame(Choreographer.java:883)
           at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1125)
           at android.os.Handler.handleCallback(Handler.java:938)
           at android.os.Handler.dispatchMessage(Handler.java:99)
           at android.os.Looper.loop(Looper.java:263)
           at android.app.ActivityThread.main(ActivityThread.java:8263)
           at java.lang.reflect.Method.invoke(Method.java)
           at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612)
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1006)
    
    opened by arjun1194 0
  • Maven Repo after JCenter shutdown

    Maven Repo after JCenter shutdown

    Hello,

    The jcenter repository is being deprecated and maintainers are advised to move to other repos, such as maven central.

    Are there plans to publish this library to another repo?

    For context: We are using this library as a dependency of react-native-video and React Native is removing the jcenter repository in it's upcoming release: https://github.com/facebook/react-native/pull/31609

    Thanks 🙌🙇‍♂️

    opened by stigi 10
Releases(v1.0.4)
Owner
Yoshihito Ikeda
Yoshihito Ikeda
VideoView that plays video only when :eyes: are open and :boy: is detected with various other features

LookAtMe VideoView that plays video only when ?? are open and ?? is detected with various other features GIF AndroidPub (Medium) Post You can read the

Pradyuman Dixit 186 Dec 13, 2022
Cache wrapper for standart android VideoView

Android VideoView cache Cache wrapper for standart android VideoView It uses okhttp and rxjava inside. Nothing special is needed to use. Setup: Add ma

Andrew0000 4 Aug 25, 2022
To play video on layout background (textureview videoview for layout designs)

The normal videoview on Android is very costly in terms of performance. Also, due to the video resolution ratio and apk size, most developers don't want to include videos in the project. With this library, developers will have a performance-friendly video background with a few lines of code.

Egemen ÖZOGUL 324 Nov 29, 2022
Is an All in One app for Muslims with lots of features such as Prayer Times & Adhan, Collections of Dhikr and Prayer sourced from Authentic Hadith, The Holy Qur'an, Qibla, Notes and many more!

Is an All in One app for Muslims with lots of features such as Prayer Times & Adhan, Collections of Dhikr and Prayer sourced from Authentic Hadith, The Holy Qur'an, Qibla, Notes and many more!

DzikirQu 112 Dec 26, 2022
Silky - Android application to convert videos from applications such as YouTube, Facebook, Twitter into audio (.mp3)

Silky Español (actualmente la app se encuentra en desarrollo ) Descripcion Aplic

null 2 Aug 24, 2022
Blade is an open source music player for Android, allowing you to play music from multiple services : files on your phone, Spotify, and more.

Blade Player Blade is an open source music player for Android, allowing you to play music from multiple services : files on your phone, Spotify, and m

Valentin HAUDIQUET 72 Jan 5, 2023
Wynncraft API Wrapper - Simple wrapper to get Wynncraft Stats of a player or a guild and more in Java

WynncraftAPIWrapper Simple wrapper to get Wynncraft Stats of a player or a guild

byBackfish 3 Sep 27, 2022
Echo is a lightweight and minimal music player for Android, built with Android Studio and written in Kotlin

Echo - Echo, A light-weight, minimal music player for Android, with shuffle, favorites and audio visualization

Divins Mathew 0 Feb 7, 2022
Free p2p cdn android github sdk to reduce video streaming costs of live and on demand video using webrtc by upto 90% and improve scalability by 6x - 🚀 Vadootv 🚀

Android p2p cdn sdk to distribute load and reduce costs(https://peervadoo.com) Vadootv is a p2p sdk integration to reduce your video streaming costs b

Vadootv 40 Oct 5, 2022
Simple and lightweight, yet polished and powerful Android video player based on ExoPlayer

Just (Video) Player Android video player based on ExoPlayer It uses ExoPlayer's extension-ffmpeg with all its audio formats enabled (it can handle eve

Marcel Dopita 677 Dec 28, 2022
Android app for streaming and downloading Movies, TV-Series and Anime.

CloudStream ⚠️ Warning: By default this app doesn't provide any video sources, you have to install extensions in order to add functionality to the app

null 309 Aug 21, 2022
Android app for streaming and downloading Movies, TV-Series and Anime.

CloudStream-3 DOWNLOAD: https://github.com/KillerDogeEmpire/Cloudstream/releases Features: AdFree, No ads whatsoever No tracking/analytics Bookmarks D

Sushil Great 3 Aug 15, 2022
Android app for streaming and downloading Movies, TV-Series and Anime.

CloudStream ⚠️ Warning: By default this app doesn't provide any video sources, you have to install extensions in order to add functionality to the app

Obaida AlBitar 2 Sep 22, 2022
A simple library for parsing and playing links from YouTube, YouTube Music, Vimeo and Rutube is WebView without the need to connect api data services. Request caching is available now

Android Oembed Video A simple library for parsing and playing links from YouTube, YouTube Music, Vimeo and Rutube and others in the WebView without th

Alexey Mostovoy 32 Oct 8, 2022
Fermata Media Player is a free, open source audio and video player with a simple and intuitive interface.

Fermata Media Player About Fermata Media Player is a free, open source audio and video player with a simple and intuitive interface. It is focused on

Andrey 227 Jan 6, 2023
A Spotify Clone that plays music and has similar UI to actual Spotify Mobile App. Made with Exoplayer and love ❤️

Spotify Clone A Spotify Clone App that can play music, and has a good looking UI that is very similar to actual Spotify Mobile App on Play Store I use

Utku Oruç 4 Oct 12, 2022
Youtube Android Clone 🚀an Android Youtube Clone made out of XML and Kotlin

Youtube Android Clone ?? This app consumes The Youtube Api to fetch and display a list of popular videos, The app uses MVVM design pattern to allow se

Breens Robert 38 Dec 13, 2022
Custom Android view with video player, loader and placeholder image

VideoPlayerView Custom Android view with video player, loader and placeholder image. To stay up-to-date with news about the library Usage Here is an e

Marcin Moskała 89 Nov 18, 2022