Skip to content

dcdhameliya/YdPlayer

Repository files navigation

YdPlayer (Android)

YdPlayer is a android library to help embed video player in your Android Application.

example:

It can be used to display video inside your app with basic(Play/Pause Control) as well as advanced(Forward/Backward + Brightness + Volume Controls) controls.

Download

Add belowed code in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

Now add below code to your app build.gradle:

android {
    ...
    compileOptions {
        targetCompatibility 1.8
    }
}
dependencies {
    ...
    implementation 'com.github.dcdhameliya:YdPlayer:0.0.1'
}

Usage

Add below code to AndroidManifest.xml file

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Add this internet permission to play video from server or any other url/link  -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- Add this read storage permission to play video from mobile device  -->

<application
    ...
    android:usesCleartextTraffic="true"
    ...>
    <activity
        ...
        android:configChanges="orientation|screenSize|keyboardHidden"
        android:screenOrientation="fullSensor"
        android:theme="@style/AppTheme"
        ...>
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Now change styles.xml for full screen video:

<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

Add view to your layout.xml & bind as usual:

<com.ykhokhaneshiya.dcdhameliya.ydplayer.YdPlayer
        android:id="@+id/yd_video"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

Actvity.java

    YdPlayer ydPlayer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // for full scrren video plyer
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.layout);
        
        // initialization of ydPlayer
        ydPlayer = findViewById(R.id.yd_video);

        // this method is used to set a video in player you can also pass local path of a video, Last parameter is a video name
        ydPlayer.setUp(this, "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4", "Local Video");

        // if you want to set thumbnail then set your thumbnail in ydPlayer.posterImageView 
        Glide.with(this).load("https://cdn.vox-cdn.com/thumbor/Pkmq1nm3skO0-j693JTMd7RL0Zk=/0x0:2012x1341/1200x800/filters:focal(0x0:2012x1341)/cdn.vox-cdn.com/uploads/chorus_image/image/47070706/google2.0.0.jpg").into(ydPlayer.posterImageView);
    }

    @Override
    protected void onPause() {
        super.onPause();

        // to pause video, it is necessary
        ydPlayer.pause();
    }

    @Override
    protected void onResume() {
        super.onResume();

        // to start a video, it is not necessary
        ydPlayer.start();
    }

You may found anoher YdPlayer library here.

You can download demo project from this link.
The password of this DemoYdPlayer.rar file is dcdhameliya.

If you want to contribute something then write me on my email: dcdhameliya@gmail.com.

© Dhruval Dhameliya Licensed under the GNU General Public License v3.0.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages