allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.nurujjmanpollob:IFramePlayerAndroidAPI:1.1'
}
add as usual xml layout like this
<dev.nurujjamanpollob.iframeplayer.NJPollobIframePlayer android:id="@+id/iframe_player" android:layout_width="match_parent" android:layout_height="250dp" />
Then initialize the view like this:
NJPollobIframePlayer iframe = findViewById(R.id.iframe_player);
DataHolder dataholder = new DataHolder();
dataholder.includeIframe("<iframe width=\"100%\" height=\"200\" src=\"https://www.youtube.com/embed/nCgQDjiotG0\" title=\"YouTube video player\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen=\"true\"></iframe>");
iframe.loadIFrameByIFrameUtility( new NJPollobIFrameUtility(dataholder).buildIFrame());
Anyway, You can direct using a key value pair to build Iframe programmatically. You can refer to this unit test class: NJPollobIFrameUtilityTest.Java to understand and run test according to your needs, I will add more unit test when I have free times.
How to programmatically build IFrame?
Look at this implementation:
DataHolder dataholder = new DataHolder();
NJPollobIFrameUtility utility = new NJPollobIFrameUtility(dataholder);
// keys in String[] Array
String[] keys = {"width", "height", "src", "title", "frameborder", "allow", "allowfullscreen"};
// values followed by keys in Array
String[] values = {"100%", "200", "https://www.youtube.com/embed/nCgQDjiotG0", "YouTube video player", "0", "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture", "true" };
dataholder.includeIframe(utility.buidIframeByKeyValue(keys, values));
// Then load it like:
NJPollobIframePlayer iframe = findViewById(R.id.iframe_player);
iframe.loadIFrameByIFrameUtility(utility.buildIFrame());
Newly Added: NJPollobYTPlayer.Java
This class is straightforward, Enable you to play YouTube Video, by simply add video token or video page url in xml or in Java Code progrmmatically like this:
With Video Page URL
<dev.nurujjamanpollob.iframeplayer.NJPollobYTPlayer
android:layout_width="match_parent"
android:layout_height="match_parent"
app:youtube_video_url="https://www.youtube.com/watch?v=0eKVizvYSUQ" />
With Video Token
<dev.nurujjamanpollob.iframeplayer.NJPollobYTPlayer
android:layout_width="match_parent"
app:youtube_video_token="nCgQDjiotG0"
android:layout_height="match_parent" />
NJPollobYTPlayer ytPlayer = findViewById(view id here);
ytPlayer.putYouTubeVideoToken(Video token here);
Or
NJPollobYTPlayer ytPlayer = findViewById(view id here);
ytPlayer.putYouTubeVideoURL(Video token here);
This class NJPollobYTPlayer.Java Offers support return it's main View and ViewGroup so you can Work with Views easily.
Applying animation, resizing ViewPort, access or re-render View is just simplified. You can call #getView(); to get parent View and getViewGroup(); to get Created ViewGroup programmatically.
I am soon gonna share documentation for this, it will be like PIP in Android OREO but covering Lower SDK.
I am having tight timeline, hope soon gonna do something with this.
Thanks :)
- PIP module Added - Need to implement in my spare time.
- Facebook IFrame Building by simply put video page URL like youtube sample.
- Vimeo Iframe builder by simply put video page URL
- Direct Video iframed by simply put URL, then The Library generates necessary codes
- More features.
* Copyright 2021 Nurujjaman Pollob.
*
* 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.