Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fast forward/rewind functionality #542

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ notifications:

language: android

env:
global:
- EMULATOR_ABI=x86_64
- EMULATOR_API=28
- EMULATOR_FLAVOR=default # use google_apis flavor if no default flavor emulator

- ADB_INSTALL_TIMEOUT=8 # minutes (2 minutes by default)

# PATH order is incredibly important. e.g. the 'emulator' script exists in more than one place!
- ANDROID_HOME=/usr/local/android-sdk
- TOOLS=${ANDROID_HOME}/tools
- PATH=${ANDROID_HOME}:${ANDROID_HOME}/emulator:${TOOLS}:${TOOLS}/bin:${ANDROID_HOME}/platform-tools:${PATH}

android:
components:
- tools
Expand All @@ -12,7 +25,32 @@ android:
- extra-android-support
- extra-android-m2repository
- extra-google-m2repository

# emulator sdk and system image
- android-${EMULATOR_API}
- sys-img-${EMULATOR_ABI}-android-${EMULATOR_API}

# downloads latest sdk tools, starts the emulator,
# disables all animations then dismisses all ANR dialogs
install:
# sdk tools are downloaded again, this is needed to get the *latest* emulator and avdmanager
# https://github.com/travis-ci/travis-ci/issues/7331#issuecomment-308416405
- echo y | sdkmanager "tools"
- echo no | avdmanager create avd --force -n test -k "system-images;android-${EMULATOR_API};${EMULATOR_FLAVOR};${EMULATOR_ABI}" -c 800M
- emulator -verbose -avd test -no-accel -delay-adb -memory 2048 -no-boot-anim -skip-adb-auth -no-window -no-snapshot -camera-back none -camera-front none -selinux permissive &

- android-wait-for-emulator

- adb shell settings put global window_animation_scale 0.0
- adb shell settings put global transition_animation_scale 0.0
- adb shell settings put global animator_duration_scale 0.0

- chmod +x ./test-tools/dismiss-system-not-responding-dialogs.sh
- ./test-tools/dismiss-system-not-responding-dialogs.sh

script:
- ./gradlew :core:connectedAndroidTest
- ./gradlew test

licenses:
- '.+'
76 changes: 43 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ android-youtube-player is a stable and customizable open source YouTube player f

To interact with YouTube the library uses the [IFrame Player API](https://developers.google.com/youtube/iframe_api_reference), inside of a WebView, therefore the YouTube app is not required on the user's device and there are [no issues with YouTube Terms of Service](#does-this-library-breaks-youtube-terms-of-service).

The web UI of the IFrame Player player is hidden. Instead, a native UI built on top of Android is used to interact with the player, providing a native experience to the users.
The web UI of the IFrame Player player is shown by default. But, by enabling an attribute ([see useNativeUi](#native-ui) a native UI built on top of Android can be used to interact with the player, providing a native experience to the users.

The UI of the player is 100% customizable. [The default UI can be changed](#playeruicontroller), to show and hide new views, or can be [completely replaced by a custom UI](#create-your-own-custom-ui).
The UI of the player is 100% customizable. [The native UI can be changed](#playeruicontroller), to show and hide new views, or can be [completely replaced by a custom UI](#create-your-own-custom-ui).

This library also provides a [Chromecast YouTube player](#chromecast-extension-library), that you can use to cast YouTube videos from your app to a Chromecast device.

Expand Down Expand Up @@ -47,7 +47,7 @@ A list of published apps that are using this library: ([let me know](https://git
The library uses YouTube's own web player to play videos. Therefore it is 100% compliant with terms of service.
[You can see here](https://developers.google.com/youtube/v3/guides/ios_youtube_helper) how this is also the official way of playing YouTube videos on iOS.

If you want to be 200% sure to be safe, [disable the native UI and enable the web player's built in web UI](#web-based-ui).
If you want to be 200% sure to be safe, [don't enable the native UI and use the web player's built in web UI](#web-based-ui).

That said how you use the library matters, be sure to play videos only when the player is visible. If you follow the instructions in the documentation, the library will automatically handle this for you.

Expand Down Expand Up @@ -87,12 +87,13 @@ Also remember when publishing your app on the PlayStore to write title and descr
2. [FadeViewHelper](#fadeviewhelper)
3. [TimeUtilities](#timeutilities)
6. [Web-based UI](#web-based-ui)
7. [Menu](#menu)
7. [Native UI](#native-ui)
8. [Menu](#menu)
1. [YouTubePlayerMenu](#youtubeplayermenu)
2. [MenuItem](#menuitem)
8. [Network events](#network-events)
9. [Chromecast support](#chromecast-support)
10. [Useful info](#useful-info)
9. [Network events](#network-events)
10. [Chromecast support](#chromecast-support)
11. [Useful info](#useful-info)
1. [Hardware acceleration](#hardware-acceleration)
2. [Play YouTube videos in the background](#play-youtube-videos-in-the-background)
3. [minSdk](#minsdk)
Expand Down Expand Up @@ -230,7 +231,7 @@ If you add the view to your XML layout you have the possibility to set a few cus
- [autoPlay](#autoPlay)
- [enableAutomaticInitialization](#enableAutomaticInitialization)
- [handleNetworkEvents](#handleNetworkEvents)
- [useWebUi](#useWebUi)
- [useNativeUi](#useNativeUi)
- [enableLiveVideoUi](#enableLiveVideoUi)
- [showYouTubeButton](#showYouTubeButton)
- [showFullScreenButton](#showFullScreenButton)
Expand Down Expand Up @@ -280,20 +281,20 @@ If you decide to set it to `false` you should also disable `enableAutomaticIniti

Read more about network events [here](#network-events).

#### useWebUi
#### useNativeUi
This attribute expects a `boolean`. Its default value is `false`.

**If `true`**, `YouTubePlayerView` will use the web-based UI of the IFrame YouTubePlayer.
**If `true`**, `YouTubePlayerView` will use the native UI of the library.

**If `false`**, `YouTubePlayerView` will use the native UI of the library.
**If `false`**, `YouTubePlayerView` will use the web-based UI of the IFrame YouTubePlayer.

YouTube added some non-removable buttons to the IFrame Player, as mentioned in [this issue](https://github.com/PierfrancescoSoffritti/android-youtube-player/issues/242). Using the web-based UI is the only way to have access to these non-removable buttons.

Read the documentation of the [`initializeWithWebUi`](#initializeWithWebUi(YouTubePlayerListener,-boolean)) method to learn more about the effects of this attribute.
Read the documentation of the [`initializeWithNativeUi`](#initializeWithNativeUi(YouTubePlayerListener,-boolean)) method to learn more about the effects of this attribute.

*Web UI screenshot:*
*Native UI screenshot:*

![web-ui screenshot](./images/web_based_ui_screenshot.jpg)
![native-ui screenshot](./images/native_ui_screenshot.jpg)

#### enableLiveVideoUi
This attribute expects a `boolean`. Its default value is `false`.
Expand All @@ -302,7 +303,7 @@ This attribute expects a `boolean`. Its default value is `false`.

**If `false`**, `YouTubePlayerView` will use the UI normal videos.

This attribute does nothing if `useWebUi` is `true`.
This attribute does nothing if `useNativeUi` is `false`.

*Live UI screenshot:*

Expand All @@ -315,7 +316,7 @@ This attribute expects a `boolean`. Its default value is `true`.

**If `false`**, `YouTubePlayerView` will not show a small clickable YouTube icon in the lower right corner of the player.

This attribute does nothing if `useWebUi` is `true`.
This attribute does nothing if `useNativeUi` is `false`.

#### showFullScreenButton
This attribute expects a `boolean`. Its default value is `true`.
Expand All @@ -324,7 +325,7 @@ This attribute expects a `boolean`. Its default value is `true`.

**If `false`**, `YouTubePlayerView` will not show a button to enter and exit full-screen.

This attribute does nothing if `useWebUi` is `true`.
This attribute does nothing if `useNativeUi` is `false`.

#### showVideoCurrentTime
This attribute expects a `boolean`. Its default value is `true`.
Expand All @@ -333,7 +334,7 @@ This attribute expects a `boolean`. Its default value is `true`.

**If `false`**, `YouTubePlayerView` will not show the current time of the current video.

This attribute does nothing if `useWebUi` is `true`.
This attribute does nothing if `useNativeUi` is `false`.

#### showVideoDuration
This attribute expects a `boolean`. Its default value is `true`.
Expand All @@ -342,7 +343,7 @@ This attribute expects a `boolean`. Its default value is `true`.

**If `false`**, `YouTubePlayerView` will not show the time duration of the current video.

This attribute does nothing if `useWebUi` is `true`.
This attribute does nothing if `useNativeUi` is `false`.

#### showSeekBar
This attribute expects a `boolean`. Its default value is `true`.
Expand All @@ -351,7 +352,7 @@ This attribute expects a `boolean`. Its default value is `true`.

**If `false`**, `YouTubePlayerView` will not show a SeekBar to control video playback.

This attribute does nothing if `useWebUi` is `true`.
This attribute does nothing if `useNativeUi` is `false`.

### Initialization
If you need to initialize `YouTubePlayerView` programmatically, you can set its xml attribute `enableAutomaticInitialization` to false.
Expand All @@ -367,7 +368,7 @@ YouTubePlayerView.initialize(YouTubePlayerListener listener)
YouTubePlayerView.initialize(YouTubePlayerListener listener, boolean handleNetworkEvents)
```
```java
YouTubePlayerView.initializeWithWebUi(YouTubePlayerListener listener, boolean handleNetworkEvents)
YouTubePlayerView.initializeWithNativeUi(YouTubePlayerListener listener, boolean handleNetworkEvents)
```
```java
YouTubePlayerView.initialize(YouTubePlayerListener listener, boolean handleNetworkEvents, IFramePlayerOptions iframePlayerOptions)
Expand All @@ -385,10 +386,8 @@ By passing an `IFramePlayerOptions` to the initialize method it is possible to s

All the possible parameters and values are listed [here](https://developers.google.com/youtube/player_parameters#Parameters). Not all of them are supported in this library because some don't make sense in this context. [Open an issue](https://github.com/PierfrancescoSoffritti/android-youtube-player/issues) if you need a parameter that is not currently supported.

#### `initializeWithWebUi(YouTubePlayerListener, boolean)`
This method is identical to `initialize(YouTubePlayerListener, boolean)` but it disables the native UI of the player and instead uses the web-based UI of the IFrame Player API.

Because the native UI is disabled trying to call `YouTubePlayerView.getPlayerUiController()` will throw an exception.
#### `initializeWithNativeUi(YouTubePlayerListener, boolean)`
This method is identical to `initialize(YouTubePlayerListener, boolean)` but it enables the native UI of the player.

YouTube added some non-removable buttons to the IFrame Player, as mentioned in [this issue](https://github.com/PierfrancescoSoffritti/android-youtube-player/issues/242). Using the web-based UI is the only way to have access to these non-removable buttons.

Expand Down Expand Up @@ -478,6 +477,8 @@ PlayerUiController YouTubePlayerView.getPlayerUiController();

[Read the documentation of PlayerUiController](#playeruicontroller).

You will need to [enable the native UI](#native-ui) to use this method.

### Release the YouTubePlayerView
Remember to release the `YouTubePlayerView` when you're done using it, by calling `YouTubePlayerView.release()`.

Expand Down Expand Up @@ -704,7 +705,9 @@ The View will be added to the top corner of the player.
![custom actions screenshot](./images/chromecast_screenshot.jpg)

## Create your own custom UI
Customization is an important aspect of this library. If need to, you can completely replace the default UI of the player.
Customization is an important aspect of this library. If need to, you can completely replace the native UI of the player.

Note: You need to enable the native UI to use a custom UI: [see useNativeUi](#native-ui)

`YouTubePlayerView` has method for that.

Expand Down Expand Up @@ -818,28 +821,35 @@ Takes in the time in seconds and returns a String with the time formatted as "M:
## Web based UI
YouTube added some non-removable buttons to the IFrame Player, as mentioned in [this issue](https://github.com/PierfrancescoSoffritti/android-youtube-player/issues/242). Using the web-based UI is the only way to have access to these non-removable buttons.

To use the web-based UI you can set the attribute `app:useWebUi="true"` in the `YouTubePlayerView`.
The web-based UI is the default UI. But if you want to use the built-in native UI, check [Native UI](#native-ui)

When using the web-based UI, calling `YouTubePlayerView.getPlayerUiController()` throws exception and it is not possible to apply any UI customization.

*This is how the player will look when using the web-based ui:*

![web-based UI](./images/web_based_ui_screenshot.jpg)

## Native UI
This is how you can enable the native UI using xml attributes

```xml
<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView
android:id="@+id/youtube_player_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"

app:useWebUi="true" />
android:useNativeUi="true" />
```

Or you can use [the appropriate initialization method](#initialization).

```java
YouTubePlayerView.initializeWithWebUi(YouTubePlayerListener listener, boolean handleNetworkEvents)
YouTubePlayerView.initializeWithNativeUi(YouTubePlayerListener listener, boolean handleNetworkEvents)
```

When using the web-based UI, calling `YouTubePlayerView.getPlayerUiController()` throws exception and it is not possible to apply any UI customization.
*This is how the player will look when using the native ui:*

*This is how the player will look when using the web-based ui:*

![web-based UI](./images/web_based_ui_screenshot.jpg)
![native UI](./images/native_ui_screenshot.jpg)

## Menu
`PlayerUiController` has an optional menu. You can use these methods to control the menu's behavior:
Expand Down
4 changes: 2 additions & 2 deletions core-sample-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@
android:hardwareAccelerated="true"
android:label="@string/iframe_player_options_example" />
<activity
android:name="com.pierfrancescosoffritti.androidyoutubeplayer.core.sampleapp.examples.webUiExample.WebUiExampleActivity"
android:name="com.pierfrancescosoffritti.androidyoutubeplayer.core.sampleapp.examples.nativeUiExample.NativeUiExampleActivity"
android:configChanges="orientation|screenSize|keyboardHidden|smallestScreenSize|screenLayout"
android:hardwareAccelerated="true"
android:label="@string/web_ui_example" />
android:label="@string/native_ui_example" />
<activity
android:name="com.pierfrancescosoffritti.androidyoutubeplayer.core.sampleapp.examples.chromecastExample.ChromeCastExampleActivity"
android:configChanges="orientation|screenSize|keyboardHidden|smallestScreenSize|screenLayout"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import com.pierfrancescosoffritti.androidyoutubeplayer.core.sampleapp.examples.recyclerViewExample.RecyclerViewActivity;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.sampleapp.examples.simpleExample.SimpleExampleActivity;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.sampleapp.examples.viewPagerExample.ViewPagerActivity;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.sampleapp.examples.webUiExample.WebUiExampleActivity;
import com.pierfrancescosoffritti.androidyoutubeplayer.core.sampleapp.examples.nativeUiExample.NativeUiExampleActivity;
import com.pierfrancescosoffritti.aytplayersample.R;
import com.psoffritti.librarysampleapptemplate.core.Constants;
import com.psoffritti.librarysampleapptemplate.core.SampleAppTemplateActivity;
Expand All @@ -38,7 +38,7 @@ protected void onCreate(Bundle savedInstanceState) {
ExampleActivityDetails[] examples = new ExampleActivityDetails[]{
new ExampleActivityDetails(R.string.simple_example,null, SimpleExampleActivity.class),
new ExampleActivityDetails(R.string.complete_example,null, CompleteExampleActivity.class),
new ExampleActivityDetails(R.string.web_ui_example,null, WebUiExampleActivity.class),
new ExampleActivityDetails(R.string.native_ui_example,null, NativeUiExampleActivity.class),
new ExampleActivityDetails(R.string.custom_ui_example,null, CustomUiActivity.class),
new ExampleActivityDetails(R.string.recycler_view_example,null, RecyclerViewActivity.class),
new ExampleActivityDetails(R.string.view_pager_example,null, ViewPagerActivity.class),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class CompleteExampleActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_basic_example);
setContentView(R.layout.activity_complete_example);

youTubePlayerView = findViewById(R.id.youtube_player_view);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pierfrancescosoffritti.androidyoutubeplayer.core.sampleapp.examples.webUiExample;
package com.pierfrancescosoffritti.androidyoutubeplayer.core.sampleapp.examples.nativeUiExample;

import android.os.Bundle;
import android.widget.Button;
Expand All @@ -13,14 +13,14 @@
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

public class WebUiExampleActivity extends AppCompatActivity {
public class NativeUiExampleActivity extends AppCompatActivity {

private YouTubePlayerView youTubePlayerView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.web_ui_example);
setContentView(R.layout.native_ui_example);

youTubePlayerView = findViewById(R.id.youtube_player_view);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView
android:id="@+id/youtube_player_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
app:useNativeUi="true" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/chromecast_controls_root"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -9,7 +9,8 @@
<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView
android:id="@+id/youtube_player_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
app:useNativeUi="true" />

<Button
android:id="@+id/next_video_button"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_height="match_parent">

<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView
android:id="@+id/youtube_player_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:layout_height="wrap_content"
app:useNativeUi="true" />
</LinearLayout>
3 changes: 2 additions & 1 deletion core-sample-app/src/main/res/layout/activity_live_video.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
android:layout_height="wrap_content"

app:enableLiveVideoUi="true"
app:showFullScreenButton="false" />
app:showFullScreenButton="false"
app:useNativeUi="true" />
</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
android:id="@+id/youtube_player_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:useNativeUi="true"

app:showFullScreenButton="false" />
</LinearLayout>
Loading