Giter Club home page Giter Club logo

uiza-android-sdk-player's Introduction

Welcome to UizaSDK

Simple Streaming at scale.

Uiza is the complete toolkit for building a powerful video streaming application with unlimited scalability. We design Uiza so simple that you only need a few lines of codes to start streaming, but sophisticated enough for you to build complex products on top of it.

Importing the Library

Step 1. Add the JitPack repository to your build file

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

Step 2. Add the dependency

defaultConfig {
  multiDexEnabled  true
}
dependencies {
  compile 'com.github.uizaio:uiza-android-sdk-player:[lasted-release-number]'
}

Init SDK

  1. appId : get in email at registration
  2. token : generate via https://docs.uiza.io/#get-api-key
  3. api : get in email at registration
 public class App extends MultiDexApplication {
        @Override
        public void onCreate() {
            super.onCreate();
            Utils.init(this);
            String api = "api";
            String token = "token";
            String appId = "appId";
            UizaDataV3.getInstance().initSDK(api, token, appId);
        }
    }

Manifest

<application
  android:name=".App "  <!-- important this line -->
  ........
  >

How to call API?:

Step1: You must extend your activity/fragment like this

public class YourActivity extends BaseActivity{
}

or

public class YourFragment extends BaseFragment{
}

make sure add this line below

UizaDataV3.getInstance().setCasty(Casty.create(this));

before super.onCreate(savedInstanceState); in onCreate() of your activity.

Step 2: Call api by using this function

UizaServiceV3 service = RestClientV3.createService(UizaServiceV3.class);
subscribe(service.getListMetadata(), new ApiSubscriber<ResultGetListMetadata>() {
    @Override
  public void onSuccess(ResultGetListMetadata resultGetListMetadata) {
        LLog.d(TAG, "getListMetadata onSuccess: " + LSApplication.getInstance().getGson().toJson(resultGetListMetadata));
    }

    @Override
  public void onFail(Throwable e) {
        LLog.e(TAG, "checkToken onFail " + e.getMessage());
    }
});

Other API can be used with the same function above.

API doc APIDOC

This class help you know how to use all Uiza API, please refer to THIS

How to play the video?:

XML

<vn.loitp.uizavideov3.view.rl.video.UizaIMAVideoV3
  android:id="@id/uiza_video"
  android:layout_width="match_parent"
  android:layout_height="wrap_content" />

JAVA

Create java file MainActivity:

public class MainActivity extends BaseActivity implements UizaCallback{
   public void isInitResult();
   public void onClickListEntityRelation();
   public void onClickBack();
   public void onClickPip();
   public void onClickPipVideoInitSuccess();
   public void onError();
}

Manifest

<activity
  android:name=".MainActivity "
  android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize|uiMode" />

In onCreate() Play with entity:

uizaIMAVideoV3 = (UizaIMAVideoV3) findViewById(R.id.uiza_video);
uizaIMAVideoV3.setUizaCallback(this);
UizaUtil.initEntity(activity, uizaIMAVideoV3, "put entity id here");

Play with playlist/folder:

UizaUtil.initPlaylistFolder(activity, uizaIMAVideoV3, "put playlist/folder id here");

Dont forget to add in activity life cycle event:

@Override
public void onDestroy() {
    super.onDestroy();
    uizaIMAVideoV3.onDestroy();
}

@Override
public void onResume() {
    super.onResume();
    uizaIMAVideoV3.onResume();
}

@Override
public void onPause() {
    super.onPause();
    uizaIMAVideoV3.onPause();
}

@Override
public void onStart() {
    super.onStart();
    uizaIMAVideoV3.onStart();
}

@Override
public void onStop() {
    super.onStop();
    uizaIMAVideoV3.onStop();
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == UizaIMAVideo.CODE_DRAW_OVER_OTHER_APP_PERMISSION) {
        if (resultCode == Activity.RESULT_OK) {
            uizaIMAVideoV3.initializePiP();
        } else {
            LToast.show(activity, "Draw over other app permission not available");
        }
    } else {
        super.onActivityResult(requestCode, resultCode, data);
    }
}

Then put

@Override
public void isInitResult(boolean b, ResultGetLinkPlay resultGetLinkPlay, ResultRetrieveAnEntity resultRetrieveAnEntity) {
    if (b) {
        uizaIMAVideoV3.setEventBusMsgFromActivityIsInitSuccess();
    }
}

All listener (If you want to listen all events)

private void setListener() {
    if (uizaIMAVideoV3 == null || uizaIMAVideoV3.getPlayer() == null) {
        return;
    }
    uizaIMAVideoV3.getPlayer().addListener(new Player.EventListener() {
        @Override
        public void onTimelineChanged(Timeline timeline, Object manifest, int reason) {
            //LLog.d(TAG, "onTimelineChanged");
        }

        @Override
        public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
            //LLog.d(TAG, "onTimelineChanged");
        }

        @Override
        public void onLoadingChanged(boolean isLoading) {
            //LLog.d(TAG, "onTimelineChanged");
        }

        @Override
        public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
            //LLog.d(TAG, "onTimelineChanged");
        }

        @Override
        public void onRepeatModeChanged(int repeatMode) {
            //LLog.d(TAG, "onTimelineChanged");
        }

        @Override
        public void onShuffleModeEnabledChanged(boolean shuffleModeEnabled) {
            //LLog.d(TAG, "onTimelineChanged");
        }

        @Override
        public void onPlayerError(ExoPlaybackException error) {
            //LLog.d(TAG, "onTimelineChanged");
        }

        @Override
        public void onPositionDiscontinuity(int reason) {
            //LLog.d(TAG, "onTimelineChanged");
        }

        @Override
        public void onPlaybackParametersChanged(PlaybackParameters playbackParameters) {
            //LLog.d(TAG, "onTimelineChanged");
        }

        @Override
        public void onSeekProcessed() {
            //LLog.d(TAG, "onTimelineChanged");
        }
    });
    uizaIMAVideoV3.getPlayer().addAudioDebugListener(new AudioRendererEventListener() {
        @Override
        public void onAudioEnabled(DecoderCounters counters) {
            //LLog.d(TAG, "onAudioEnabled");
        }

        @Override
        public void onAudioSessionId(int audioSessionId) {
            //LLog.d(TAG, "onAudioSessionId");
        }

        @Override
        public void onAudioDecoderInitialized(String decoderName, long initializedTimestampMs, long initializationDurationMs) {
            //LLog.d(TAG, "onAudioDecoderInitialized");
        }

        @Override
        public void onAudioInputFormatChanged(Format format) {
            //LLog.d(TAG, "onAudioInputFormatChanged");
        }

        @Override
        public void onAudioSinkUnderrun(int bufferSize, long bufferSizeMs, long elapsedSinceLastFeedMs) {
            //LLog.d(TAG, "onAudioSinkUnderrun");
        }

        @Override
      public void onAudioDisabled(DecoderCounters counters) {
            //LLog.d(TAG, "onAudioDisabled");
       }
    });
    uizaIMAVideoV3.setProgressCallback(new ProgressCallback() {
        @Override
       public void onAdProgress(float currentMls, int s, float duration, int percent) {
            //LLog.d(TAG, TAG + " ad progress: " + currentMls + "/" + duration + " -> " + percent + "%");
       }

        @Override
        public void onVideoProgress(float currentMls, int s, float duration, int percent) {
            //LLog.d(TAG, TAG + " video progress: " + currentMls + "/" + duration + " -> " + percent + "%");
        }
    });
    uizaIMAVideoV3.getPlayer().addVideoDebugListener(new VideoRendererEventListener() {
        @Override
       public void onVideoEnabled(DecoderCounters counters) {
            //LLog.d(TAG, "onVideoEnabled");
       }

        @Override
       public void onVideoDecoderInitialized(String decoderName, long initializedTimestampMs, long initializationDurationMs) {
            //LLog.d(TAG, "onVideoDecoderInitialized");
       }

        @Override
       public void onVideoInputFormatChanged(Format format) {
            //LLog.d(TAG, "onVideoInputFormatChanged");
       }

        @Override
       public void onDroppedFrames(int count, long elapsedMs) {
            //LLog.d(TAG, "onDroppedFrames");
       }

        @Override
       public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
            //LLog.d(TAG, "onAudioDisabled");
       }

        @Override
       public void onRenderedFirstFrame(Surface surface) {
            //LLog.d(TAG, "onRenderedFirstFrame");
       }

        @Override
      public void onVideoDisabled(DecoderCounters counters) {
            //LLog.d(TAG, "onVideoDisabled");
       }
    });
    uizaIMAVideoV3.getPlayer().addMetadataOutput(new MetadataOutput() {
        @Override
       public void onMetadata(Metadata metadata) {
            //LLog.d(TAG, "onMetadata");
       }
    });
    uizaIMAVideoV3.getPlayer().addTextOutput(new TextOutput() {
        @Override
       public void onCues(List<Cue> cues) {
            //LLog.d(TAG, "onCues");
       }
    });
}

Listener touch event

uizaIMAVideoV3.setOnTouchEvent(new UizaPlayerView.OnTouchEvent() {
    @Override
    public void onSingleTapConfirmed() {
        LLog.d(TAG, "onSingleTapConfirmed");
    }

    @Override
    public void onLongPress() {
        LLog.d(TAG, "onLongPress");
    }

    @Override
    public void onDoubleTap() {
        LLog.d(TAG, "onDoubleTap");
    }

    @Override
    public void onSwipeRight() {
        LLog.d(TAG, "onSwipeRight");
    }

    @Override
    public void onSwipeLeft() {
        LLog.d(TAG, "onSwipeLeft");
    }

    @Override
    public void onSwipeBottom() {
        LLog.d(TAG, "onSwipeBottom");
    }

    @Override
    public void onSwipeTop() {
        LLog.d(TAG, "onSwipeTop");
    }
});

This sample help you know how to use all Uiza SDK, please refer to THIS

How to livestream with UizaSDK?:

It's very easy, plz follow these step below: XML:

<vn.loitp.uizavideov3.view.rl.livestream.UizaLivestream  
  android:id="@+id/uiza_livestream"  
  android:layout_width="match_parent"  
  android:layout_height="match_parent" />

In class LivestreamBroadcasterActivity:

public class LivestreamBroadcasterActivity extends BaseActivity implements  UizaLivestream.Callback {
...
}

func onCreate():

getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);  
getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
uizaLivestream = (UizaLivestream) findViewById(R.id.uiza_livestream);  
uizaLivestream.setCallback(this);
uizaLivestream.setId("Put the entity id for livestream here");

Then put this line on surfaceChanged(UizaLivestream.StartPreview startPreview);

startPreview.onSizeStartPreview(1280, 720);

Start a livestream:

if (uizaLivestream.prepareAudio() && uizaLivestream.prepareVideoHD(false)) {  
    uizaLivestream.startStream(uizaLivestream.getMainStreamUrl());  
}

Start a livestream and save to mp4 file:

if (uizaLivestream.prepareAudio() && uizaLivestream.prepareVideoHD(false)) {  
    uizaLivestream.startStream(uizaLivestream.getMainStreamUrl(), true);  
}

Stop streaming (It auto save mp4 file in your gallery if you start a livestream with option save local file)

uizaLivestream.stopStream();

Switch camera:

uizaLivestream.switchCamera();

This sample help you know how to use all Uiza SDK for livestream, please refer to THIS

Docs

Docs

Support

Please feel free to contact me anytime: [email protected]

License

UizaSDK is released under the BSD license. See LICENSE for details.

uiza-android-sdk-player's People

Contributors

gj-loitp avatar

Watchers

James Cloos avatar LiaoQingfu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.