Skip to content

ArslanKathia/ExoPlayer-Wrapper

 
 

Repository files navigation

Download License

ExoPlayer-Wrapper

Simpe ExoPlayer wrapper

Installation

  • Add the dependency from jCenter to your app's (not project) build.gradle file:
repositories {
    jcenter()
}

dependencies {
    compile 'net.alexandroid.utils:exoplayerhelper:2.09'
}

How to use it

Add view:

    <com.google.android.exoplayer2.ui.SimpleExoPlayerView
        android:id="@+id/exoPlayerView"
        android:layout_width="match_parent"
        android:layout_height="200dp"/>

And in your code:

public class MainActivity extends AppCompatActivity 
        implements ExoPlayerListener, ExoAdListener{
        
    public static final String SAMPLE_1 = "http://...video.m3u8";
    public static final String TEST_TAG_URL = "https://pubads.g.doubleclick.net/...";
    private ExoPlayerHelper mExoPlayerHelper;

...

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

        SimpleExoPlayerView exoPlayerView = findViewById(R.id.exoPlayerView);

        mExoPlayerHelper = new ExoPlayerHelper.Builder(this, exoPlayerView)
                .addMuteButton(false, false)
                .setUiControllersVisibility(false)
                .setRepeatModeOn(true)
                .setAutoPlayOn(false)
                .setVideoUrls(SAMPLE_1)
                .setTagUrl(TEST_TAG_URL)
                .setExoPlayerEventsListener(this)
                .setExoAdEventsListener(this)
                .addSavedInstanceState(savedInstanceState)
                .setThumbImageViewEnabled(this)
                .enableLiveStreamSupport()
                .createAndPrepare();
}


// Lifecycle events

@Override
protected void onSaveInstanceState(Bundle outState) {
    mExoPlayerHelper.onSaveInstanceState(outState);
    super.onSaveInstanceState(outState);
}

@Override
protected void onStart() {
    super.onStart();
    mExoPlayerHelper.onActivityStart();
}

@Override
protected void onResume() {
    super.onResume();
    mExoPlayerHelper.onActivityResume();
}

@Override
protected void onPause() {
    super.onPause();
    mExoPlayerHelper.onActivityPause();
}

@Override
protected void onStop() {
    super.onStop();
    mExoPlayerHelper.onActivityStop();
}

@Override
protected void onDestroy() {
    super.onDestroy();
    mExoPlayerHelper.onActivityDestroy();
}

// ExoPlayerListener methods

@Override
public void onThumbImageViewReady(ImageView imageView) {
    Picasso.with(this)
            .load(THUMB_IMG_URL)
            .placeholder(R.drawable.place_holder)
            .error(R.drawable.error_image)
            .into(imageView);
}

@Override
public void onLoadingStatusChanged(boolean isLoading, long bufferedPosition, int bufferedPercentage) {}

@Override
public void onPlayerPlaying(int currentWindowIndex) {}

@Override
public void onPlayerPaused(int currentWindowIndex) {}

@Override
public void onPlayerBuffering(int currentWindowIndex) {}

@Override
public void onPlayerStateEnded(int currentWindowIndex) {}

@Override
public void onPlayerStateIdle(int currentWindowIndex) {}

@Override
public void onPlayerError(String errorString) {}

@Override
public void createExoPlayerCalled(boolean isToPrepare) {}

@Override
public void releaseExoPlayerCalled() {}

@Override
public void onVideoResumeDataLoaded(int window, long position, boolean isResumeWhenReady) {}

@Override
public void onVideoTapped() {}

@Override
public boolean onPlayBtnTap() {
    return false;
}

@Override
public boolean onPauseBtnTap() {
    return false;
}

@Override
public void onTracksChanged(int currentWindowIndex, int nextWindowIndex, boolean isPlayBackStateReady) {}

@Override
public void onMuteStateChanged(boolean isMuted) {}


// ExoAdListener methods

@Override
public void onAdPlay() {}

@Override
public void onAdPause() {}

@Override
public void onAdResume() {}

@Override
public void onAdEnded() {}

@Override
public void onAdError() {}

@Override
public void onAdLoadError() {}

@Override
public void onAdClicked() {}

@Override
public void onAdTapped() {}




License

Copyright 2017 Alexey Korolev

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.

About

Android library, ExoPlayer wrapper (2017)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%