Skip to content
This repository was archived by the owner on Jul 20, 2021. It is now read-only.

Commit 14ab9ba

Browse files
committed
Adding dependency through jitpack
1 parent f6575a2 commit 14ab9ba

20 files changed

+757
-215
lines changed

Diff for: .idea/.name

-1
This file was deleted.

Diff for: .idea/encodings.xml

-6
This file was deleted.

Diff for: README.md

+315-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,92 @@ Better Video Player is a rethought version(fork) of [Easy Video Player](https://
44

55
<img src="https://raw.githubusercontent.com/halilozercan/bettervideoplayer/master/screens/fullscreen.png" width="600px" />
66

7+
##### Features
8+
9+
* *Based on the stock MediaPlayer API.* It will work on all devices and all CPUs, and it works with both local and remote sources.
10+
* *Simple.* Much less code is required than alternative options to get up and running.
11+
* *Very configurable.* There are lots of options available to make the player behave exactly how you want it to behave.
12+
* *Adaptive.* The player use the colors of your (AppCompat) Activity theme automatically.
13+
14+
---
15+
16+
## Gradle Dependency
17+
18+
[![Release](https://jitpack.io/v/halilozercan/BetterVideoPlayer.svg)]
19+
(https://jitpack.io/#halilozercan/BetterVideoPlayer)
20+
[![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg?style=flat-square)](https://www.apache.org/licenses/LICENSE-2.0.html)
21+
22+
The Gradle dependency is available via [![Release](https://jitpack.io/v/halilozercan/BetterVideoPlayer.svg)]
23+
(https://jitpack.io/#halilozercan/BetterVideoPlayer)
24+
25+
### Dependency
26+
27+
Add this to your app/build.gradle repositories:
28+
29+
```gradle
30+
maven { url 'https://jitpack.io' }
31+
```
32+
33+
Add this in your module's `build.gradle` file:
34+
35+
```gradle
36+
dependencies {
37+
// ... other dependencies
38+
compile ''com.github.halilozercan:BetterVideoPlayer:0.1.0'
39+
}
40+
```
41+
42+
43+
## Getting Started
44+
45+
##### Configuring a Player Activity
46+
47+
You will need an `Activity` in your app that will hold the `BetterVideoPlayer` view and playback content.
48+
There's only a bit of configuration required.
49+
50+
*First, the Activity needs to use a theme from Google AppCompat. Here's an example from the sample project:*
51+
52+
```xml
53+
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
54+
55+
<item name="colorPrimary">@color/primary</item>
56+
<item name="colorPrimaryDark">@color/primary_dark</item>
57+
<item name="colorAccent">@color/accent</item>
58+
59+
</style>
60+
```
61+
62+
*Second, the Activity should disable recreation on orientation changes. This allows playback to continue
63+
when the device orientation changes. The player will adapt the aspect ratio accordingly. You just need to
64+
set `android:configChanges` values to your `Activity` in `AndroidManifest.xml`:*
65+
66+
```xml
67+
<activity
68+
android:name=".MyPlayerActivity"
69+
android:label="@string/my_player_activity"
70+
android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
71+
android:theme="@style/AppTheme" /> <!-- Don't need to set the theme here if it's set on your <application /> tag already -->
72+
```
73+
74+
##### Layouts
75+
76+
The layout for your player Activity can be very simple. You only need a `BetterVideoPlayer` view,
77+
all the controls and everything else are created by the player view itself.
78+
79+
```xml
80+
<com.halilibo.bettervideoplayer.BetterVideoPlayer
81+
xmlns:android="http://schemas.android.com/apk/res/android"
82+
android:id="@+id/player"
83+
android:layout_width="match_parent"
84+
android:layout_height="match_parent" />
85+
```
86+
87+
Before moving onto code setup, here is a list of changes that are made to EasyVideoPlayer.
88+
789
#### Easy Video Player
890

9-
Most of the features from Easy Video Player are still available.
10-
You can go to source repository and check the well written documentation and README to get started.
11-
This document will go through the added and removed features.
91+
Most of the features from Easy Video Player is still available.
92+
This document will include added and removed features.
1293

1394
## Removed Features
1495

@@ -72,6 +153,237 @@ mostly used media players like VLC or MX Player. This feature lets your users to
72153
familiar with your video player. For now, this option cannot be disabled but this will
73154
be possible in the future.
74155

156+
##### Code Setup
157+
158+
Since your `Activity` is using an AppCompat theme, make sure it extends `AppCompatActivity`.
159+
160+
Initializing the player is very simple. You just set a callback listener to receive notifications of
161+
important events, and a source.
162+
163+
```java
164+
public class MyPlayerActivity extends AppCompatActivity implements BetterVideoCallback {
165+
166+
private static final String TEST_URL = "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4";
167+
168+
private BetterVideoPlayer player;
169+
170+
@Override
171+
protected void onCreate(Bundle savedInstanceState) {
172+
super.onCreate(savedInstanceState);
173+
setContentView(R.layout.activity_myplayer);
174+
175+
// Grabs a reference to the player view
176+
player = (BetterVideoPlayer) findViewById(R.id.player);
177+
178+
// Sets the callback to this Activity, since it inherits EasyVideoCallback
179+
player.setCallback(this);
180+
181+
// Sets the source to the HTTP URL held in the TEST_URL variable.
182+
// To play files, you can use Uri.fromFile(new File("..."))
183+
player.setSource(Uri.parse(TEST_URL));
184+
185+
// From here, the player view will show a progress indicator until the player is prepared.
186+
// Once it's prepared, the progress indicator goes away and the controls become enabled for the user to begin playback.
187+
}
188+
189+
@Override
190+
public void onPause() {
191+
super.onPause();
192+
// Make sure the player stops playing if the user presses the home button.
193+
player.pause();
194+
}
195+
196+
// Methods for the implemented EasyVideoCallback
197+
198+
@Override
199+
public void onStarted(BetterVideoPlayer player) {
200+
//Log.i(TAG, "Started");
201+
}
202+
203+
@Override
204+
public void onPaused(BetterVideoPlayer player) {
205+
//Log.i(TAG, "Paused");
206+
}
207+
208+
@Override
209+
public void onPreparing(BetterVideoPlayer player) {
210+
//Log.i(TAG, "Preparing");
211+
}
212+
213+
@Override
214+
public void onPrepared(BetterVideoPlayer player) {
215+
//Log.i(TAG, "Prepared");
216+
}
217+
218+
@Override
219+
public void onBuffering(int percent) {
220+
//Log.i(TAG, "Buffering " + percent);
221+
}
222+
223+
@Override
224+
public void onError(BetterVideoPlayer player, Exception e) {
225+
//Log.i(TAG, "Error " +e.getMessage());
226+
}
227+
228+
@Override
229+
public void onCompletion(BetterVideoPlayer player) {
230+
//Log.i(TAG, "Completed");
231+
}
232+
233+
@Override
234+
public void onToggleControls(BetterVideoPlayer player, boolean isShowing) {
235+
//Log.i(TAG, "Controls toggled " + isShowing);
236+
}
237+
}
238+
```
239+
240+
You can see almost identical code in action in the sample project.
241+
242+
---
243+
244+
## Programmatic Control
245+
246+
Here's a list of methods that can be used to control the `BetterVideoPlayer` programmatically.
247+
Methods used to change behavior are discussed in the next section.
248+
249+
```java
250+
BetterVideoPlayer player = // ...
251+
252+
// Sets a video source to be played.
253+
player.setSource(Uri);
254+
255+
// Sets a callback to receive normal player events.
256+
player.setCallback(EasyVideoCallback);
257+
258+
// Sets a callback that can be used to retrieve updates of the current playback position.
259+
player.setProgressCallback(EasyVideoProgressCallback);
260+
261+
// Starts or resumes playback.
262+
player.start();
263+
264+
// Seeks to a position in the video.
265+
player.seekTo(int);
266+
267+
// Pauses playback.
268+
player.pause();
269+
270+
// Stops playback.
271+
player.stop();
272+
273+
// Resets the player, allowing a new source to be set.
274+
player.reset();
275+
276+
// Releases the underlying MediaPlayer and cleans up resources.
277+
player.release();
278+
279+
// Shows the default controls. They can be hidden again if the user taps the player.
280+
player.showControls();
281+
282+
// Hides the default controls. They can be shown again if the user taps the player.
283+
player.hideControls().
284+
285+
// Shows the controls if they're hidden, hides them if they're shown.
286+
player.toggleControls();
287+
288+
// Returns true if the default controls are currently shown.
289+
player.isControlsShown();
290+
291+
// Hide the default controls and prevents them from being shown.
292+
player.disableControls();
293+
294+
// Undoes disableControls()
295+
player.enableControls();
296+
297+
// Returns true if the player has prepared for playback entirely
298+
player.isPrepared();
299+
300+
// Returns true if the player is NOT paused.
301+
player.isPlaying();
302+
303+
// Returns the current position of playback.
304+
player.getCurrentPosition();
305+
306+
// Returns the total duration of the video.
307+
player.getDuration();
308+
```
309+
310+
---
311+
312+
## Programmatic Configuration
313+
314+
There are a options that can be used to change the default behavior of the `EasyVideoPlayer`:
315+
316+
```java
317+
BetterVideoPlayer player = // ...
318+
319+
// Defaults to true. The controls fade out when playback starts.
320+
player.setHideControlsOnPlay(boolean);
321+
322+
// Defaults to false. Immediately starts playback when the player becomes prepared.
323+
player.setAutoPlay(boolean);
324+
325+
// Sets a position that will be skipped to right when the player becomes prepared. Only happens once when set.
326+
player.setInitialPosition(int);
327+
328+
// Sets a custom drawable for the left restart action.
329+
player.setRestartDrawable(Drawable);
330+
player.setRestartDrawableRes(int);
331+
332+
// Sets a custom drawable for the play button.
333+
player.setPlayDrawable(Drawable);
334+
player.setPlayDrawableRes(int);
335+
336+
// Sets a custom drawable for the pause button.
337+
player.setPauseDrawable(Drawable);
338+
player.setPauseDrawableRes(int);
339+
340+
// Sets a theme color that is used to color the seekbar and loading icon.
341+
// Defaults to your activity's primary theme color.
342+
player.setThemeColor(int);
343+
player.setThemeColorRes(int);
344+
345+
// Sets the left and right volume levels. The player must be prepared first.
346+
player.setVolume(float, float);
347+
348+
// Sets whether or not the player will start playback over when reaching the end.
349+
player.setLoop(false);
350+
351+
// Registers a caption source
352+
player.setCaptions(Uri, mimeType);
353+
354+
// Sets a style from SpinKit.
355+
player.setLoadingStyle(int);
356+
357+
// Sets the current window. Useful when you want to enable brightness setting in swipe.
358+
player.setWindow(Window);
359+
```
360+
361+
---
362+
363+
## XML Configuration
364+
365+
The programmatic configuration options shown above can also be configured directly from your layout:
366+
367+
```xml
368+
<com.afollestad.easyvideoplayer.EasyVideoPlayer xmlns:android="http://schemas.android.com/apk/res/android"
369+
xmlns:app="http://schemas.android.com/apk/res-auto"
370+
android:id="@+id/player"
371+
android:layout_width="match_parent"
372+
android:layout_height="match_parent"
373+
app:bvp_autoPlay="false"
374+
app:bvp_disableControls="false"
375+
app:bvp_hideControlsOnPlay="true"
376+
app:bvp_pauseDrawable="@drawable/bvp_action_pause"
377+
app:bvp_playDrawable="@drawable/bvp_action_play"
378+
app:bvp_restartDrawable="@drawable/bvp_action_restart"
379+
app:bvp_source="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"
380+
app:bvp_themeColor="@color/color_primary"
381+
app:bvp_captionSize="22sp"
382+
app:bvp_captionColor="@color/caption_color"
383+
app:bvp_loadingStyle="DoubleBounce"
384+
app:bvp_loop="false" />
385+
```
386+
75387
#### Final note
76388
While I try to complete this README, you can check out Sample project of this repo. It will be updated often and
77389
written code sometimes help a lot more than a poorly written documentation.

Diff for: app/build.gradle

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 24
5-
buildToolsVersion "24.0.0"
4+
compileSdkVersion project.compileSdkVersion
5+
buildToolsVersion project.buildToolsVersion
66

77
defaultConfig {
88
applicationId "com.halilibo.bettervideoplayer"
9-
minSdkVersion 15
10-
targetSdkVersion 24
9+
minSdkVersion project.minSdkVersion
10+
targetSdkVersion project.targetSdkVersion
1111
versionCode 1
1212
versionName "1.0"
1313
}
@@ -22,7 +22,7 @@ android {
2222
dependencies {
2323
compile fileTree(dir: 'libs', include: ['*.jar'])
2424
compile project(':library')
25-
compile 'com.android.support:appcompat-v7:24.2.1'
26-
compile 'com.android.support:support-compat:24.2.1'
27-
compile 'com.android.support:support-v4:24.2.1'
25+
compile "com.android.support:appcompat-v7:$project.googleAPIsVersion"
26+
compile "com.android.support:support-compat:$project.googleAPIsVersion"
27+
compile "com.android.support:support-v4:$project.googleAPIsVersion"
2828
}

0 commit comments

Comments
 (0)