Skip to content

inventos/FlockPlay-android

Repository files navigation

FlockPlay Android

Description of the technology

FlockPlay technology for the Android platform is a proxy server and P2P module.

Requirements

Before you use the library, make sure that you have the correct version of the compiler JAVA - 1.7. or higher.

  • The library has been developed for the platform Android 4.0 or higher.
  • Currently it supports processor architectures - armeabi-v7a (armv7) and ia32 (x86).

Version of the compiler

Before you use the library, make sure that you have the correct version of the compiler JAVA - 1.7. or higher.

Setup

Next, you need to download the following library files. To avoid errors, use the recommended libs!

Name Recommended version JAR armeabi armeabi-v7a x86 x86_64 arm64-v8a
android-async-http 1.4.6 android-async-http-1.4.6.jar - - - - -
tyrus-standalone-client 1.10 tyrus-standalone-client-1.10.jar - - - - -
libjingle_peerconnection - libjingle_peerconnection.jar - libjingle_peerconnection_so.so libjingle_peerconnection_so.so - -
android-flockplay 2 android-flockplay-2.jar - - - - -

Now add the JAR files to the libs project and SO files in the folders libs/armeabi-v7a and libs/x86.

Next, add files to project build path.

Editing manifest

Add in AndroidManifest.xml file the following permissions:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> 

and information about the current SDK:

<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21"/> 

Usage

First, fill the structure ru.inventos.flockplay.p2p.Options. It has several fields:

  • Options.tag - translation identifier.
  • Options.key - key.

Next you have to implement interface and send object to server constructor.

public interface AbstractMediaPlayer {
    public int getCurrentPositionMs ();
}

Where:

public int getCurrentPositionMs();

returns current playback position in milliseconds.

Constructor interface:

public ProxyServer (Options o, Context c,AbstractMediaPlayer p);

Example could look like this:

VideoView player = ...;
AbstractMediaPlayer abstractMediaPlayer = new AbstractMediaPlayer() {
    @Override
    public int getCurrentPositionMs() {
        return player.getCurrentPosition();
    }
};
ProxyServer server = new ProxyServer(ops,getContext(),abstractMediaPlayer);

After creating the server does not automatically start. Therefore, run it by:

public boolean open ()

If the call returns false - then launch failed. Now the server is running is the last step - prepare URL playlist. For this purpose the method:

public android.net.Uri preparePlaylist (java.lang.String u)

The resulting object is passed to the video player.

In order to permanently shut down the server, use this method:

public void shutdown (android.content.Context c)

Traffic

Using the information about the current internet connection (Wi-Fi, 4G or 3G / 2G) plugin can automatically disable the ability to serve the files. In order to globally block the uploading of files (data about the internet connection will not be affected by this flag), you must call the class ru.inventos.flockplay.p2p.ProxyServer:

public void setSendingDisabled (boolean f)

It should be noted that the possibility of a forced enable file uploading not provided.

Example

Using the server class with VideoView:

ExampleActivity.java

public class ExampleActivity extends Activity {

    private ProxyServer mProxyServer;
    private VideoView mVideoView;

    @Override
    public void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.example_layout);
        mVideoView = (VideoView)findViewById(R.id.video_view);
        Options options = new Options();
        options.tag = "github";
        options.key = "demo";
        AbstractMediaPlayer abstractMediaPlayer = new AbstractMediaPlayer() {
            @Override
            public int getCurrentPositionMs() {
                return mVideoView.getCurrentPosition();
            }
        };
        mProxyServer = new ProxyServer(options,this,abstractMediaPlayer);
        mProxyServer.open()
    }

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

    @Override
    public void onStart () {
        super.onStart();
        mProxyServer.resume();
        mVideoView.setVideoURI(mProxyServer.preparePlaylist("http://flockplay.com/test/playlist.m3u8"));
        mVideoView.requestFocus();
        mVideoView.start();
    }

    @Override
    protected void onDestroy() {
        mProxyServer.shutdown(this);
        super.onDestroy();
    }

}

Possible problems and their solutions

  • An error occurred while building the project in Android Studio: "Unable to execute DX"

Solution: Go to the "Project Structure" -> "Facets" -> "Packaging" -> Uncheck "Pre-dex external jars and Android library dependencies"

About

Peer-to-peer video delivery for Android

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages