Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修正音频播放崩溃的问题 #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ owspace是一款高仿单读的APP,API接口通过非法手段获取。<br>
* jsoup解析DOM
* sqldelight SqlBrite
* 音视频播放等
* Android6.0 动态权限申请 easypermissions
* some fucking source code

# 里程碑列表
# 里程碑列表
### 2018/11/14 修正音频播放crash问题
### 2018/3/27 升级API Level到27,各种依赖包全部升级
### 2017/11/27 更新gradle、更新相关dependencies版本
### 2016/11/25 添加音频播放
Expand All @@ -28,6 +30,8 @@ owspace是一款高仿单读的APP,API接口通过非法手段获取。<br>


# 展示
![image](art/permission1.png) ![image](art/permission2.png)

![image](art/show1.png) ![image](art/show2.png)

![image](art/show3.png) ![image](art/show4.png)
Expand All @@ -50,9 +54,9 @@ owspace是一款高仿单读的APP,API接口通过非法手段获取。<br>
# thanks
```
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:recyclerview-v7:27.1.0'
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
implementation(name: 'SildeMenulibrary-release', ext: 'aar')
Expand Down
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def time = String.format("%d%02d%02d%d%d", calendar.get(Calendar.YEAR), calendar
def name = time+"build";
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
// buildToolsVersion '27.0.3'
defaultConfig {
applicationId "com.github.baby.owspace"
minSdkVersion 16
Expand Down Expand Up @@ -42,9 +42,9 @@ repositories{

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:recyclerview-v7:27.1.0'
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
implementation(name: 'SildeMenulibrary-release', ext: 'aar')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package com.github.baby.owspace.player;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Binder;
import android.os.Build;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v4.app.NotificationCompat;
import android.widget.RemoteViews;

Expand Down Expand Up @@ -116,7 +122,7 @@ public boolean pause() {

@Override
public boolean isPlaying() {
return mPlayer.isPlaying();
return mPlayer != null && mPlayer.isPlaying();
}
public String getSong(){
return mPlayer.getSong();
Expand Down Expand Up @@ -178,8 +184,18 @@ private void showNotification(PlayState status) {
// The PendingIntent to launch our activity if the user selects this notification
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);

// startForeground fail after upgrade to Android 8.1, because Builder(context) has deprecated, we must
// use Builder(context, channel) instead of
// https://stackoverflow.com/questions/47531742/startforeground-fail-after-upgrade-to-android-8-1
String channel;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
channel = createChannel();
else {
channel = "";
}

// Set the info for the views that show in the notification panel.
Notification notification = new NotificationCompat.Builder(this)
Notification notification = new NotificationCompat.Builder(this, channel)
.setSmallIcon(R.mipmap.ic_launcher) // the status icon
.setWhen(System.currentTimeMillis()) // the time stamp
.setContentIntent(contentIntent) // The intent to send when the entry is clicked
Expand All @@ -192,6 +208,30 @@ private void showNotification(PlayState status) {
startForeground(NOTIFICATION_ID, notification);
}

/**
* startForeground fail after upgrade to Android 8.1
* https://stackoverflow.com/questions/47531742/startforeground-fail-after-upgrade-to-android-8-1
* @return
*/
@RequiresApi(api = Build.VERSION_CODES.O)
private synchronized String createChannel() {
NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

String name = "snap map fake location ";
int importance = NotificationManager.IMPORTANCE_LOW;

NotificationChannel mChannel = new NotificationChannel("snap map channel", name, importance);

mChannel.enableLights(true);
mChannel.setLightColor(Color.BLUE);
if (mNotificationManager != null) {
mNotificationManager.createNotificationChannel(mChannel);
} else {
stopSelf();
}
return "snap map channel";
}

private RemoteViews getSmallContentView() {
if (mContentViewSmall == null) {
mContentViewSmall = new RemoteViews(getPackageName(), R.layout.remote_view_music_player_small);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public boolean pause() {

@Override
public boolean isPlaying() {
return mPlayer.isPlaying();
return mPlayer != null && mPlayer.isPlaying();
}

@Override
Expand Down
Binary file added art/permission1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added art/permission2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 13 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

buildscript {
repositories {
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}
google()
jcenter()
// maven {
// url 'https://maven.google.com/'
// name 'Google'
// }

mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
// classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
// NOTE: Do not place your application dependencies here; they belong
Expand All @@ -21,11 +22,13 @@ buildscript {

allprojects {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com/'
name 'Google'
}

// maven {
// url 'https://maven.google.com/'
// name 'Google'
// }
}
}

Expand Down