Skip to content

Commit

Permalink
Merge pull request #311 from Johnny1994/dev
Browse files Browse the repository at this point in the history
release v2.4.1
  • Loading branch information
KevinHuo authored Feb 18, 2020
2 parents b2f2869 + 5a11bc4 commit 7f7d72b
Show file tree
Hide file tree
Showing 62 changed files with 593 additions and 46 deletions.
24 changes: 12 additions & 12 deletions PLDroidMediaStreamingDemo/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion '27.0.3'
compileSdkVersion 28
buildToolsVersion '28.0.3'

defaultConfig {
applicationId "com.qiniu.pili.droid.streaming.demo"
minSdkVersion 15
targetSdkVersion 23
versionCode 68
versionName "2.4.0"
minSdkVersion 16
targetSdkVersion 28
versionCode 69
versionName "2.4.1"
}
buildTypes {
release {
Expand All @@ -20,10 +20,10 @@ android {
}

dependencies {
compile 'com.github.angads25:filepicker:1.0.6'
compile 'com.qiniu:happy-dns:0.2.8'
compile 'com.journeyapps:zxing-android-embedded:3.0.2@aar'
compile 'com.google.zxing:core:3.2.0'
compile 'com.android.support:appcompat-v7:23.0.0'
compile files('libs/pldroid-media-streaming-2.4.0.jar')
implementation 'com.github.angads25:filepicker:1.0.6'
implementation 'com.qiniu:happy-dns:0.2.8'
implementation 'com.journeyapps:zxing-android-embedded:3.0.2@aar'
implementation 'com.google.zxing:core:3.2.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation files('libs/pldroid-media-streaming-2.4.1.jar')
}
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions PLDroidMediaStreamingDemo/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-feature
Expand Down Expand Up @@ -64,6 +65,7 @@
<activity
android:name="com.qiniu.pili.droid.streaming.screen.ScreenCaptureRequestActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"></activity>
<service android:name=".service.KeepAppAliveService" />
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
public class MainActivity extends FragmentActivity {
private static final String TAG = "MainActivity";

private static final String GENERATE_STREAM_TEXT = "http://api-demo.qnsdk.com/v1/live/stream/";
private static final String GENERATE_STREAM_TEXT = "https://api-demo.qnsdk.com/v1/live/stream/";

private static final String[] INPUT_TYPES = { "Authorized", "Unauthorized" };
private static final String[] STREAM_TYPES = { "Video-Audio", "Audio", "Import", "Screen" };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,65 @@
package com.qiniu.pili.droid.streaming.demo;

import android.app.Application;
import android.content.Intent;

import com.qiniu.pili.droid.streaming.StreamingEnv;
import com.qiniu.pili.droid.streaming.demo.service.KeepAppAliveService;
import com.qiniu.pili.droid.streaming.demo.utils.AppStateTracker;

public class StreamingApplication extends Application {

private boolean mIsServiceAlive;
private Intent mServiceIntent;

@Override
public void onCreate() {
super.onCreate();
/**
* init must be called before any other func
*/
StreamingEnv.init(getApplicationContext());

/**
* track app background state to avoid possibly stopping microphone recording
* in screen streaming mode on Android P+
*/
AppStateTracker.track(this, new AppStateTracker.AppStateChangeListener() {
@Override
public void appTurnIntoForeground() {
stopService();
}

@Override
public void appTurnIntoBackGround() {
startService();
}

@Override
public void appDestroyed() {
stopService();
}
});
}

/**
* start foreground service to make process not turn to idle state
*
* on Android P+, it doesn't allow recording audio to protect user's privacy in idle state.
*/
private void startService() {
if (mServiceIntent == null) {
mServiceIntent = new Intent(StreamingApplication.this, KeepAppAliveService.class);
}
startService(mServiceIntent);
mIsServiceAlive = true;
}

private void stopService() {
if (mIsServiceAlive) {
stopService(mServiceIntent);
mServiceIntent = null;
mIsServiceAlive = false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.qiniu.pili.droid.streaming.demo.service;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.IBinder;
import android.support.annotation.Nullable;

import com.qiniu.pili.droid.streaming.demo.R;

public class KeepAppAliveService extends Service {
private NotificationManager mNotificationManager;
private String mNotificationId = "keepAppAliveId";
private String mNotificationName = "Keep app alive";

@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}

@Override
public void onCreate() {
super.onCreate();
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(mNotificationId, mNotificationName, NotificationManager.IMPORTANCE_HIGH);
mNotificationManager.createNotificationChannel(channel);
}
startForeground(1, getNotification());
}

private Notification getNotification() {
Notification.Builder builder = new Notification.Builder(this)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("七牛推流")
.setContentText("后台运行中");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
builder.setChannelId(mNotificationId);
}
return builder.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package com.qiniu.pili.droid.streaming.demo.utils;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;

public class AppStateTracker {
public static final int STATE_FOREGROUND = 0;

public static final int STATE_BACKGROUND = 1;

private static int currentState;

public static int getCurrentState() {
return currentState;
}

public interface AppStateChangeListener {
void appTurnIntoForeground();
void appTurnIntoBackGround();
void appDestroyed();
}

public static void track(Application application, final AppStateChangeListener appStateChangeListener){

application.registerActivityLifecycleCallbacks(new SimpleActivityLifecycleCallbacks(){

private int resumeActivityCount = 0;
private int createActivityCount = 0;

@Override
public void onActivityCreated(Activity activity, Bundle bundle) {
createActivityCount++;
}

@Override
public void onActivityStarted(Activity activity) {
if (resumeActivityCount==0){
currentState = STATE_FOREGROUND;
appStateChangeListener.appTurnIntoForeground();
}

resumeActivityCount++;
}

@Override
public void onActivityStopped(Activity activity) {
resumeActivityCount--;

if (resumeActivityCount==0){
currentState = STATE_BACKGROUND;
appStateChangeListener.appTurnIntoBackGround();
}
}

@Override
public void onActivityDestroyed(Activity activity) {
createActivityCount--;

if (createActivityCount == 0) {
appStateChangeListener.appDestroyed();
}
}
});
}

private static class SimpleActivityLifecycleCallbacks implements Application
.ActivityLifecycleCallbacks{

@Override
public void onActivityCreated(Activity activity, Bundle bundle) {

}

@Override
public void onActivityStarted(Activity activity) {

}

@Override
public void onActivityResumed(Activity activity) {

}

@Override
public void onActivityPaused(Activity activity) {

}

@Override
public void onActivityStopped(Activity activity) {

}

@Override
public void onActivitySaveInstanceState(Activity activity, Bundle bundle) {

}

@Override
public void onActivityDestroyed(Activity activity) {

}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions PLDroidMediaStreamingDemo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
}
}

Expand Down
Loading

0 comments on commit 7f7d72b

Please sign in to comment.