All Projects → halilozercan → Bettervideoplayer

halilozercan / Bettervideoplayer

Video playback on Android, made better in Kotlin, wrapping around the stock MediaPlayer API.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Bettervideoplayer

dart vlc
🎞 Flutter audio / video playback, broadcast & recording library for Windows & Linux.
Stars: ✭ 439 (+65.04%)
Mutual labels:  video-player, playback
Shaka Player
JavaScript player library / DASH & HLS client / MSE-EME player
Stars: ✭ 5,386 (+1924.81%)
Mutual labels:  video-player, playback
api.video-player-sdk
SDK to control and interact with the api.video HTML5 Player
Stars: ✭ 31 (-88.35%)
Mutual labels:  video-player, playback
Shaka Player Embedded
Shaka Player in a C++ Framework
Stars: ✭ 153 (-42.48%)
Mutual labels:  video-player, playback
shaka-player-react
A simple React component wrapper for shaka-player
Stars: ✭ 79 (-70.3%)
Mutual labels:  video-player, playback
Straas-android-sdk-sample
Straas Android SDK samples and documentation
Stars: ✭ 12 (-95.49%)
Mutual labels:  playback
synchroplayer
Synchronized video player for watching videos together remotely.
Stars: ✭ 25 (-90.6%)
Mutual labels:  video-player
floating-video-player-android
Floating VideoPlayer sample project with plugin
Stars: ✭ 17 (-93.61%)
Mutual labels:  video-player
vue3-video-play
适用于 Vue3 的 hls.js 播放器组件,配置丰富,界面还算好看
Stars: ✭ 108 (-59.4%)
Mutual labels:  video-player
Myflix
Myflix, a Netflix clone!
Stars: ✭ 260 (-2.26%)
Mutual labels:  video-player
react-native-vimeo-iframe
No description or website provided.
Stars: ✭ 17 (-93.61%)
Mutual labels:  video-player
Android-VimeoPlayer
Unofficial Vimeo video player library for Android.
Stars: ✭ 46 (-82.71%)
Mutual labels:  video-player
Image-Processing
A set of algorithms and other cool things that I learned while doing image processing with openCV using C++ and python.
Stars: ✭ 29 (-89.1%)
Mutual labels:  video-player
X1Player
iOS端封装的视频播放器.支持直播,录播视频的播放,支持常用的播放界面控制,类似于ijkplayer 优点是体积更小,使用快捷
Stars: ✭ 21 (-92.11%)
Mutual labels:  video-player
cast control
📺 Control Chromecasts from Linux and D-Bus
Stars: ✭ 443 (+66.54%)
Mutual labels:  playback
framework
A creative coding library.
Stars: ✭ 35 (-86.84%)
Mutual labels:  video-player
Super-Stitch
一款视频超级拼接软件
Stars: ✭ 28 (-89.47%)
Mutual labels:  video-player
vue-h5-video
基于vue的H5视频播放器
Stars: ✭ 65 (-75.56%)
Mutual labels:  video-player
KingPlayer
🎬 一个专注于 Android 视频播放器的基础库,无缝切换内核。(IjkPlayer、ExoPlayer、VlcPlayer、MediaPlayer)
Stars: ✭ 35 (-86.84%)
Mutual labels:  video-player
moe.TV
watch bangumi on your tvOS
Stars: ✭ 25 (-90.6%)
Mutual labels:  video-player

DEPRECATED - This project is deprecated. I suggest you to look for alternatives like ExoPlayer.

Better Video Player

Features
  • Completely written in Kotlin.
  • Based on the stock MediaPlayer API It will work on all devices and all CPUs, and it works with both local and remote sources.
  • Simple Much less code is required than alternative options to get up and running.
  • Very configurable There are lots of options available to make the player behave exactly how you want it to behave.
  • Swipe Gestures Supports the common on-screen scroll behavior which is used by MXPlayer, VLC and other Android video players.
  • Tap Gestures Double tap on right or left side of the screen to jump back and forward like Youtube and Netflix players.

Gradle Dependency

Release License

The Gradle dependency is available via jitpack

Dependency

Add this to your app/build.gradle repositories:

maven { url 'https://jitpack.io' }

Add this in your module's build.gradle file:

dependencies {
    // ... other dependencies
    compile 'com.github.halilozercan:BetterVideoPlayer:kotlin-SNAPSHOT'
}

Getting Started

Configuring a Player Activity

You will need an Activity in your app that will hold the BetterVideoPlayer view and playback content. There's only a bit of configuration required. However, BetterVideoPlayer offers great 'customizability'.

Host Activity should disable recreation on orientation changes. This allows playback to continue when the device orientation changes. The player will adapt the aspect ratio accordingly. You just need to set android:configChanges values to your Activity in AndroidManifest.xml:

<activity
    android:name=".MyPlayerActivity"
    android:label="@string/my_player_activity"
    android:configChanges="orientation|keyboardHidden|screenLayout|screenSize" /> 
Layouts

The layout for your player Activity can be very simple. You only need a BetterVideoPlayer view, all the controls and everything else are created by the player itself.

<com.halilibo.bvpkotlin.BetterVideoPlayer
    android:id="@+id/player"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

Notable Features

BetterVideoPlayer is capable of almost all functionality that you expect from a VideoPlayer. However, it is important to repeat that BetterVideoPlayer uses Android MediaPlayer API. Thus, it does not provide every codec in the world. In the future, there is a plan for moving underlying player to ExoPlayer.

Captions

BetterVideoPlayer supports captions in 2 formats; SRT and WEBVTT. Support for more formats through pull requests will be appreciated.

Captions can be obtained both online and from resource directory. BetterVideoPlayer currently does not support captions from local file storage.

// Online SUBRIP subtitle
bvp.setCaptions("https://www.example.com/subrip.srt", CaptionsView.SubMime.SUBRIP)

// res/raw SUBRIP subtitle
bvp.setCaptions(R.raw.sub, CaptionsView.SubMime.SUBRIP)

BetterVideoPlayer also lets you define the text size(in sp) and color of captions inside XML view.

<com.halilibo.bvpkotlin.BetterVideoPlayer
        android:id="@+id/bvp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        bvp:bvp_captionSize="20sp"
        bvp:bvp_captionColor="@android:color/holo_blue_light"/>

Toolbar

BetterVideoPlayer deploys a common toolbar at the top of the player. Toolbar is useful in a video player in two different ways.

  • It offers a highly customizable Title area.
  • You can inflate a menu on the toolbar and define as many actions as you need.

To access toolbar, just use getToolbar() method. You can also show and hide the toolbar by using showToolbar() and hideToolbar(). Besides these methods, it is not recommended to alter Toolbar's visibility.

Swipe Gestures

Swipe Gestures on a video player are proved to be very useful by MX, VLC and others. Swiping left and right to seek to any point in video or swipe up and down to control volume and brightness. BetterVideoPlayer comes with built-in support for these gestures. This feature enables developers to have a player that their users are familiar with.

You can enable or disable gestures by enableSwipeGestures() and disableSwipeGestures() methods.

Important point: You need to use enableSwipeGestures(Window) method to also enable brightness control. Brightness setting needs a reference window.

Gestures

Code Setup

Initializing the player is very simple. You just set a callback listener and a source.

class MyPlayerActivity : AppCompatActivity , BetterVideoCallback {

    lateinit var player: BetterVideoPlayer

    override fun onCreate(savedInstanceState: Bundle) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_myplayer)

        // Grab a reference to the player view
        player = findViewById(R.id.player)

        // Set the source to the HTTP URL held in the TEST_URL variable.
        // To play files, you can use Uri.fromFile(new File("..."))
        player.setSource(Uri.parse(TEST_URL))

        // From here, the player view will show a progress indicator until the player is prepared.
        // Once it's prepared, the progress indicator goes away and the controls become enabled for the user to begin playback.
    }

    override fun onPause() {
        super.onPause()
        // Make sure the player stops playing if the user presses the home button.
        player.pause()
    }
    
    companion object {
        const val TEST_URL = "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
    }
}

You can see the almost identical code in action in the sample project.


Programmatic Control

Here's a list of methods that can be used to control the BetterVideoPlayer programmatically. Full list of available methods is in IBetterVideoPlayer interface.

val player: BetterVideoPlayer = findViewById<BetterVideoPlayer>(R.id.bvp)

// Sets a video source to be played.
player.setSource(Uri)

// Sets a callback to receive normal player events.
player.setCallback(VideoCallBack)

// Sets a callback that can be used to retrieve updates of the current playback position.
player.setProgressCallback(VideoProgressCallback)

// Starts or resumes playback.
player.start()

// Seeks to a position in the video.
player.seekTo(int)

// Pauses playback.
player.pause()

// Stops playback.
player.stop()

// Resets the player, allowing a new source to be set.
player.reset()

// Releases the underlying MediaPlayer and cleans up resources.
player.release()

// Shows the default controls. They can be hidden again if the user taps the player.
player.showControls()

// Hides the default controls. They can be shown again if the user taps the player.
player.hideControls()

// Shows the controls if they're hidden, hides them if they're shown.
player.toggleControls()

// Enables double tap to seek like in Youtube. Input: seek time in milliseconds
player.enableDoubleTapSeek(int)

// Returns true if the default controls are currently shown.
player.isControlsShown()

// Hide the default controls and prevents them from being shown.
player.disableControls()

// Undoes disableControls()
player.enableControls()

// Returns true if the player has prepared for playback entirely
player.isPrepared()

// Returns true if the player is NOT paused.
player.isPlaying()

// Returns the current position of playback.
player.getCurrentPosition()

// Returns the total duration of the video.
player.getDuration()

Programmatic Configuration

There are options that can be used to change the default behavior of the BetterVideoPlayer:

val player: BetterVideoPlayer = findViewById<BetterVideoPlayer>(R.id.bvp)

// Defaults to true. The controls fade out when playback starts.
player.setHideControlsOnPlay(boolean)

// Defaults to false. Immediately starts playback when the player becomes prepared.
player.setAutoPlay(boolean)

// Sets a position that will be skipped to right when the player becomes prepared. Only happens once when set.
player.setInitialPosition(int)

// Sets a custom drawable for play, pause and restart button states.
player.setButtonDrawable(ButtonType, Drawable)

// Sets the left and right volume levels. The player must be prepared first.
player.setVolume(float, float)

// Sets whether or not the player will start playback over when reaching the end.
player.setLoop(false)

// Registers a caption source
player.setCaptions(Uri, mimeType)

XML Configuration

The programmatic configuration options shown above can also be configured directly from your layout:

<com.halilibo.bvpkotlin.BetterVideoPlayer
    android:id="@+id/player"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:bvp_autoPlay="false"
    app:bvp_disableControls="false"
    app:bvp_hideControlsOnPlay="true"
    app:bvp_pauseDrawable="@drawable/bvp_action_pause"
    app:bvp_playDrawable="@drawable/bvp_action_play"
    app:bvp_restartDrawable="@drawable/bvp_action_restart"
    app:bvp_source="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
    app:bvp_captionSize="22sp"
    app:bvp_captionColor="@color/caption_color"
    app:bvp_gestureType="SwipeGesture"
    app:bvp_loop="false" />

Shoutouts

You can find one of, if not, the best coding tutorials in Turkish at https://mobilhanem.com

En iyi Türkçe yazılım eğitimleri için https://mobilhanem.com

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].