-
Notifications
You must be signed in to change notification settings - Fork 0
Android video
- Description of the technology
- Requirements
- Video player connection
- Setup
- Editing manifest
- Usage
- Traffic
- Example
- Possible problems and their solutions
FlockPlay technology for the Android platform is a proxy server and P2P module.
Before you use the library, make sure that you have the correct version of the compiler JAVA - 1.6. or higher.
- The library has been developed for the platform Android 4.0 or higher.
- Currently it supports processor architectures - armeabi-v7a (armv7), ia32 (x86) and arm64-v8a (armv8).
Before you use the library, make sure that you have the correct version of the compiler JAVA - 1.6. or higher.
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.4 | android-async-http-1.4.4.jar | - | - | - | - | - |
| autobahn-ws | 0.5.0 | autobahn-0.5.0.jar | - | - | - | - | - |
| libjingle_peerconnection | 3.52 | libjingle_peerconnection.jar | - | libjingle_peerconnection_so.so | libjingle_peerconnection_so.so | - | - |
| android-flockplay | - | android-flockplay.jar | - | - | - | - | - |
Now add the JAR files to the libs project and SO files in the folders libs/armeabi-v7a, libs/x86 and libs/arm64-v8a.
Next, add files to project build path.
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"/> First, fill the structure ru.inventos.flockplay.p2p.ProxyServer.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 getCurrentPosition ();
public boolean isPlaying();
}Where:
public int getCurrentPosition();returns current playback position in milliseconds.
Constructor interface:
public ProxyServer (ProxyServer.Options o, Context c,AbstractMediaPlayer p);Example could look like this:
VideoView player = ...;
AbstractMediaPlayer abstractMediaPlayer = new AbstractMediaPlayer() {
@Override
public int getCurrentPosition() {
return player.getCurrentPosition();
}
@Override
public boolean isPlaying() {
return player.isPlaying();
}
};
ProxyServer server = new ProxyServer(ops,getContext(),abstractMediaPlayer);After creating the server does not automatically start. Therefore, run it by:
public boolean start (int p)The only argument is the port number. 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 destroy (android.content.Context c)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.
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);
ProxyServer.Options options = new ProxyServer.Options();
options.tag = "github";
options.key = "demo";
AbstractMediaPlayer abstractMediaPlayer = new AbstractMediaPlayer() {
@Override
public int getCurrentPosition() {
return mVideoView.getCurrentPosition();
}
@Override
public boolean isPlaying() {
return mVideoView.isPlaying();
}
};
mProxyServer = new ProxyServer(options,this,abstractMediaPlayer);
}
@Override
public void onStop () {
mProxyServer.pause();
super.onStop();
}
@Override
public void onStart () {
super.onStart();
if (mProxyServer.start(8089)) {
mVideoView.setVideoURI(mProxyServer.preparePlaylist("http://flockplay.com/test/playlist.m3u8"));
mVideoView.requestFocus();
mVideoView.start();
}
}
@Override
protected void onDestroy() {
mProxyServer.destroy(this);
super.onDestroy();
}
}- 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"
