diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml
new file mode 100644
index 0000000..2f633b6
--- /dev/null
+++ b/.github/workflows/android.yml
@@ -0,0 +1,26 @@
+name: Android CI
+
+on:
+ push:
+ branches: [ "main" ]
+ pull_request:
+ branches: [ "main" ]
+
+jobs:
+ build:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v4
+ - name: set up JDK 11
+ uses: actions/setup-java@v4
+ with:
+ java-version: '11'
+ distribution: 'temurin'
+ cache: gradle
+
+ - name: Grant execute permission for gradlew
+ run: chmod +x gradlew
+ - name: Build with Gradle
+ run: ./gradlew build
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..61a9130
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml
new file mode 100644
index 0000000..d67c625
--- /dev/null
+++ b/.idea/deploymentTargetSelector.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/deviceManager.xml b/.idea/deviceManager.xml
new file mode 100644
index 0000000..a6c0bfd
--- /dev/null
+++ b/.idea/deviceManager.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index ac6b0ae..7b3006b 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -4,17 +4,16 @@
-
-
+
-
+
-
+
diff --git a/.idea/migrations.xml b/.idea/migrations.xml
new file mode 100644
index 0000000..f8051a6
--- /dev/null
+++ b/.idea/migrations.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 37a7509..1776bbc 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,6 +1,6 @@
-
+
diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml
index 7f68460..72f00ed 100644
--- a/.idea/runConfigurations.xml
+++ b/.idea/runConfigurations.xml
@@ -3,6 +3,14 @@
+
+
+
+
+
+
+
+
diff --git a/README.md b/README.md
index e13d98c..3a5267f 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,2 @@
# zz-android-old
+> use API 33 to build and api 28 to test
diff --git a/app/build.gradle b/app/build.gradle
index c4de5a6..9c9be5a 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -2,13 +2,13 @@ apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
- compileSdkVersion 30
+ compileSdkVersion 33
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "tw.music.streamer"
- minSdkVersion 21
- targetSdkVersion 30
+ minSdkVersion 27
+ targetSdkVersion 33
renderscriptTargetApi 30
renderscriptSupportModeEnabled true
versionCode 27301
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 5251f6c..5a007af 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -5,6 +5,8 @@
+
+
+
+
+
-
-
@@ -39,95 +42,115 @@
android:host="openapp"
android:scheme="zrytezene" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ android:label="ZryteZene Background Service"
+ android:exported="true"/>
+
diff --git a/app/src/main/java/tw/music/streamer/MainActivity.java b/app/src/main/java/tw/music/streamer/MainActivity.java
index 663ca6e..df21fc7 100644
--- a/app/src/main/java/tw/music/streamer/MainActivity.java
+++ b/app/src/main/java/tw/music/streamer/MainActivity.java
@@ -797,7 +797,11 @@ private void initializeLogic() {
}
private boolean _checkPermission() {
- return !(androidx.core.content.ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE) == android.content.pm.PackageManager.PERMISSION_DENIED || androidx.core.content.ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == android.content.pm.PackageManager.PERMISSION_DENIED);
+ if (Build.VERSION.SDK_INT < 33) {
+ return !(androidx.core.content.ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE) == android.content.pm.PackageManager.PERMISSION_DENIED || androidx.core.content.ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == android.content.pm.PackageManager.PERMISSION_DENIED);
+ } else {
+ return true;
+ }
}
@Override
diff --git a/app/src/main/java/tw/music/streamer/StreamerActivity.java b/app/src/main/java/tw/music/streamer/StreamerActivity.java
index bf81da4..02dbad8 100644
--- a/app/src/main/java/tw/music/streamer/StreamerActivity.java
+++ b/app/src/main/java/tw/music/streamer/StreamerActivity.java
@@ -16,6 +16,8 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
+import android.content.IntentFilter;
+import android.content.BroadcastReceiver;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
@@ -121,6 +123,9 @@
import java.util.HashMap;
import java.util.Random;
+import tw.music.streamer.adaptor.ZryteZeneAdaptor;
+import tw.music.streamer.service.ZryteZenePlay;
+
public class StreamerActivity extends AppCompatActivity {
private FirebaseDatabase _firebase = FirebaseDatabase.getInstance();
@@ -301,7 +306,6 @@ public class StreamerActivity extends AppCompatActivity {
private double _t;
private ArrayAdapter Listview2Adapter;
private GridView listview2;
- private ZryteZeneServiceBinder tmservice;
private Handler dataHandlerReceiverZero;
private Handler dataHandlerReceiverOne;
private Handler dataHandlerReceiverTwo;
@@ -312,78 +316,7 @@ public class StreamerActivity extends AppCompatActivity {
private androidx.viewpager.widget.ViewPager viewPager;
private android.graphics.drawable.AnimationDrawable rocketAnimation;
private ProgressDialog coreprog;
- private ServiceConnection serviceConnection = new ServiceConnection() {
- @Override
- public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
- tmservice = (ZryteZeneServiceBinder) iBinder;
- tmservice.setContext(getApplicationContext());
-
- dataHandlerReceiverZero = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- _updateTime();
- }
- };
-
- tmservice.setDataHandler(dataHandlerReceiverZero, 0);
-
- dataHandlerReceiverOne = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- _mpPreparedListener();
- }
- };
-
- tmservice.setDataHandler(dataHandlerReceiverOne, 1);
-
- dataHandlerReceiverTwo = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- _mpBufferingUpdate(msg.what);
- }
- };
-
- tmservice.setDataHandler(dataHandlerReceiverTwo, 2);
-
- dataHandlerReceiverThree = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- _mpCompletionListener();
- }
- };
-
- tmservice.setDataHandler(dataHandlerReceiverThree, 3);
-
- dataHandlerReceiverFour = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- _mpErrorListener(tmservice._tmpFour);
- }
- };
-
- tmservice.setDataHandler(dataHandlerReceiverFour, 4);
-
- dataHandlerReceiverFive = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- _handleMpError(tmservice._tmpFive);
- }
- };
-
- tmservice.setDataHandler(dataHandlerReceiverFive, 5);
-
- tmservice.initializeTM();
- fb_likes.addChildEventListener(_fb_likes_child_listener);
- }
-
- @Override
- public void onServiceDisconnected(ComponentName componentName) {
-
- }
- };
-
- {
- }
+ private ZryteZeneAdaptor zz;
@Override
protected void onCreate(Bundle _savedInstanceState) {
@@ -517,6 +450,13 @@ public void onClick(View _v) {
data = getSharedPreferences("teamdata", Activity.MODE_PRIVATE);
Auth = FirebaseAuth.getInstance();
d = new AlertDialog.Builder(this);
+ zz = new ZryteZeneAdaptor(this);
+ Intent siop = new Intent(getApplicationContext(), ZryteZenePlay.class);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ startForegroundService(siop);
+ } else {
+ startService(siop);
+ }
image_drawer.setOnClickListener(new View.OnClickListener() {
@Override
@@ -763,6 +703,7 @@ public void onClick(View _view) {
}
}
}
+ zz.requestAction("update-sp","loop");
}
});
@@ -773,12 +714,12 @@ public void onClick(View _view) {
if (data.getString("nightcore", "").equals("1")) {
data.edit().putString("nightcore", "0").commit();
image_nightcore.setAlpha((float) (0.5d));
- tmservice._setNightcore(1.00f);
+ //tmservice._setNightcore(1.00f);
} else {
data.edit().putString("nightcore", "1").commit();
image_nightcore.setAlpha((float) (1.0d));
float _tmpFloat = 1.10f + ((float) Double.parseDouble(data.getString("nightcoreSpeed", "")) * 0.05f);
- tmservice._setNightcore(_tmpFloat);
+ //tmservice._setNightcore(_tmpFloat);
}
} else {
data.edit().putString("nightcore", "0").commit();
@@ -847,18 +788,11 @@ public void onProgressChanged(SeekBar _param1, int _param2, boolean _param3) {
@Override
public void onStartTrackingTouch(SeekBar _param1) {
- if (!tmservice._isMpNull()) {
- tmservice._mpPause();
- tmservice._removeFocus();
- }
}
@Override
public void onStopTrackingTouch(SeekBar _param2) {
- if (!tmservice._isMpNull()) {
- tmservice._mpSeek(seekbar1.getProgress() * 1000);
- tmservice._requestFocus();
- }
+ zz.requestAction("seek", seekbar1.getProgress() * 1000);
}
});
@@ -880,12 +814,12 @@ public void onClick(View _view) {
image_play.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View _view) {
- if (tmservice._isPlaying()) {
+ /*if (tmservice._isPlaying()) {
tmservice._mpPause();
tmservice._removeFocus();
} else {
tmservice._requestFocus();
- }
+ }*/
}
});
@@ -1046,8 +980,8 @@ public void onChildRemoved(DataSnapshot _param1) {
obj.setDuration(500);
obj.start();
_customNav(theme_map.get(0).get("colorBackground").toString());
- tmservice._removeFocus();
- tmservice._resetMp();
+ //tmservice._removeFocus();
+ //tmservice._resetMp();
currentlyMap.clear();
currentlyChild.clear();
}
@@ -1057,12 +991,12 @@ public void onChildRemoved(DataSnapshot _param1) {
upload_list.remove(childkey.indexOf(_childKey));
childkey.remove(childkey.indexOf(_childKey));
}
- if (!tmservice._isMpNull() && currentlyChild != null) {
- if (currentlyChild.contains(_childKey)) {
- currentlyMap.remove(currentlyChild.indexOf(_childKey));
- currentlyChild.remove(currentlyChild.indexOf(_childKey));
- }
- }
+ //if (!tmservice._isMpNull() && currentlyChild != null) {
+ //if (currentlyChild.contains(_childKey)) {
+ //currentlyMap.remove(currentlyChild.indexOf(_childKey));
+ //currentlyChild.remove(currentlyChild.indexOf(_childKey));
+ //}
+ //}
int _index = listview1.getFirstVisiblePosition();
View _view = listview1.getChildAt(0);
int _top = (_view == null) ? 0 : _view.getTop();
@@ -1695,7 +1629,6 @@ public void onClick(View _view) {
public void onComplete(Task _param1) {
final boolean _success = _param1.isSuccessful();
final String _errorMessage = _param1.getException() != null ? _param1.getException().getMessage() : "";
-
}
};
@@ -1704,7 +1637,6 @@ public void onComplete(Task _param1) {
public void onComplete(Task _param1) {
final boolean _success = _param1.isSuccessful();
final String _errorMessage = _param1.getException() != null ? _param1.getException().getMessage() : "";
-
}
};
@@ -1712,7 +1644,6 @@ public void onComplete(Task _param1) {
@Override
public void onComplete(Task _param1) {
final boolean _success = _param1.isSuccessful();
-
}
};
}
@@ -1789,8 +1720,8 @@ public boolean onTouch(View p1, MotionEvent p2) {
obj.setDuration(500);
obj.start();
_customNav(theme_map.get(0).get("colorBackground").toString());
- tmservice._removeFocus();
- tmservice._resetMp();
+ //tmservice._removeFocus();
+ //tmservice._resetMp();
currentlyMap.clear();
currentlyChild.clear();
}
@@ -1956,11 +1887,28 @@ public void onItemClick(AdapterView parent, View view, int _pos, long id) {
}
}
_firebase_storage.getReferenceFromUrl("https://firebasestorage.googleapis.com/v0/b/teammusic-tw.appspot.com/o/tm-testfile?alt=media&token=ec852b8b-438c-457a-887d-b289968971ec").getFile(new File(FileUtil.getPackageDataDir(getApplicationContext()).concat("/tm-testfile"))).addOnSuccessListener(_check_quota_download_success_listener).addOnFailureListener(_check_quota_failure_listener).addOnProgressListener(_check_quota_download_progress_listener);
+ IntentFilter filr = new IntentFilter(ZryteZenePlay.ACTION_UPDATE);
+ registerReceiver(listenerReceiver, filr);
+ zz.requestAction("request-media");
/*
Glide.with(getApplicationContext()).load(Uri.parse("c")).into(image_album);
*/
}
+ private BroadcastReceiver listenerReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent != null && intent.getAction() != null) {
+ if (intent.getAction().equals(ZryteZenePlay.ACTION_UPDATE)) {
+ String m = intent.getStringExtra("update");
+ if (m.equals("on-prepared")) {
+ _CoreProgressLoading(false);
+ }
+ }
+ }
+ }
+ };
+
@Override
protected void onActivityResult(int _requestCode, int _resultCode, Intent _data) {
super.onActivityResult(_requestCode, _resultCode, _data);
@@ -2004,11 +1952,11 @@ public void onBackPressed() {
_setMenu(tabsPos);
_abandonFocus();
} else {
- if (!tmservice._isMpNull()) {
- moveTaskToBack(true);
- } else {
- finish();
- }
+ //if (!tmservice._isMpNull()) {
+ //moveTaskToBack(true);
+ //} else {
+ //finish();
+ //}
}
}
}
@@ -2028,7 +1976,7 @@ public void onStart() {
image_user.clearColorFilter();
_drawer_image_user.clearColorFilter();
}
- if (tmservice != null) {
+ /*if (tmservice != null) {
if (!currentlyPlaying.equals("") && !tmservice._isMpNull()) {
if (currentlyMap.get(currentlyChild.indexOf(currentlyPlaying)).containsKey("img")) {
image_album.clearColorFilter();
@@ -2039,26 +1987,23 @@ public void onStart() {
text_artist.setTextColor(Color.parseColor(theme_map.get(0).get("colorPrimaryCardText").toString()));
}
}
- }
+ }*/
((BaseAdapter) listview1.getAdapter()).notifyDataSetChanged();
}
@Override
public void onResume() {
super.onResume();
-
}
@Override
public void onPause() {
super.onPause();
-
}
@Override
public void onStop() {
super.onStop();
-
}
@Override
@@ -2217,8 +2162,8 @@ private void _loadTheme() {
text_zene.setTextColor(Color.parseColor(theme_map.get(0).get("colorBackgroundCardText").toString()));
text_playlist.setTextColor(Color.parseColor(theme_map.get(0).get("colorBackgroundCardText").toString()));
edittext_search.setTextColor(Color.parseColor(theme_map.get(0).get("colorBackgroundCardText").toString()));
- x_tab.setSelectedTabIndicatorColor(Color.parseColor(theme_map.get(0).get("colorPrimary").toString()));
- x_tab.setTabTextColors(Color.parseColor(theme_map.get(0).get("colorBackgroundText").toString()), Color.parseColor(theme_map.get(0).get("colorBackgroundText").toString()));
+ //x_tab.setSelectedTabIndicatorColor(Color.parseColor(theme_map.get(0).get("colorPrimary").toString()));
+ //x_tab.setTabTextColors(Color.parseColor(theme_map.get(0).get("colorBackgroundText").toString()), Color.parseColor(theme_map.get(0).get("colorBackgroundText").toString()));
{
ViewGroup _vg = (ViewGroup) x_tab.getChildAt(0);
@@ -2318,13 +2263,13 @@ private void _loadTheme() {
}
private void _refreshLikes() {
- if (!tmservice._isMpNull()) {
+ //if (!tmservice._isMpNull()) {
if (likeChild.contains(currentlyPlaying.concat(FirebaseAuth.getInstance().getCurrentUser().getUid()))) {
image_favs.setImageResource(R.drawable.ic_favorite);
} else {
image_favs.setImageResource(R.drawable.ic_favorite_border);
}
- }
+ //}
}
private void _CoreProgressLoading(final boolean _ifShow) {
@@ -2702,9 +2647,9 @@ public void onClick(DialogInterface _dialog, int _which) {
private void _play(final String _key) {
_CoreProgressLoading(true);
- tmservice._resetMp();
+ //tmservice._resetMp();
final double _position = currentlyChild.indexOf(_key);
- tmservice._playSongFromURL(currentlyMap.get((int) _position).get("url").toString());
+ //tmservice._playSongFromURL(currentlyMap.get((int) _position).get("url").toString());
currentlyPlaying = _key;
text_title.setText(currentlyMap.get((int) _position).get("name").toString());
if (usrname_list.contains(currentlyMap.get((int) _position).get("uid").toString())) {
@@ -2724,6 +2669,7 @@ private void _play(final String _key) {
image_album.setImageResource(R.drawable.ic_album_white);
image_album.setColorFilter(Color.parseColor(theme_map.get(0).get("colorButtonText").toString()), PorterDuff.Mode.MULTIPLY);
}
+ zz.requestAction("play", currentlyMap.get((int) _position).get("url").toString());
}
private void _NewTapTarget(final View _view, final String _title, final String _msg, final String _bgcolor) {
@@ -2789,14 +2735,14 @@ private void _mpPreparedListener() {
if (data.getString("nightcore", "").equals("1")) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
float _tmpFloat = 1.10f + ((float) Double.parseDouble(data.getString("nightcoreSpeed", "")) * 0.05f);
- tmservice._setNightcore(_tmpFloat);
+ //tmservice._setNightcore(_tmpFloat);
} else {
data.edit().putString("nightcore", "0").commit();
image_nightcore.setAlpha((float) (0.5d));
_customSnack("Android Lollipop or lower doesn't support nightcore feature!", 2);
}
}
- tmservice._requestFocus();
+ //tmservice._requestFocus();
_CoreProgressLoading(false);
_refreshLikes();
if (openNum == 0) {
@@ -2806,8 +2752,8 @@ private void _mpPreparedListener() {
upload_map = currentlyMap.get((int) _position);
upload_map.put("view", String.valueOf((long) (Double.parseDouble(upload_map.get("view").toString()) + 1)));
upload_text.child(currentlyPlaying).updateChildren(upload_map);
- text_duration.setText(new DecimalFormat("00").format(tmservice._getSongDuration() / 60000).concat(":".concat(new DecimalFormat("00").format((tmservice._getSongDuration() / 1000) % 60))));
- seekbar1.setMax(tmservice._getSongDuration() / 1000);
+ //text_duration.setText(new DecimalFormat("00").format(tmservice._getSongDuration() / 60000).concat(":".concat(new DecimalFormat("00").format((tmservice._getSongDuration() / 1000) % 60))));
+ //seekbar1.setMax(tmservice._getSongDuration() / 1000);
}
private void _mpErrorListener(final String _errorMsg) {
@@ -2822,15 +2768,16 @@ private void _mpErrorListener(final String _errorMsg) {
obj.setDuration(500);
obj.start();
_customNav(theme_map.get(0).get("colorBackground").toString());
- tmservice._removeFocus();
- tmservice._resetMp();
+ //tmservice._removeFocus();
+ //tmservice._resetMp();
+ zz.clear();
currentlyMap.clear();
currentlyChild.clear();
}
private void _mpBufferingUpdate(final double _percent) {
try {
- seekbar1.setSecondaryProgress(((int) _percent * tmservice._getSongDuration()) / 100000);
+ //seekbar1.setSecondaryProgress(((int) _percent * tmservice._getSongDuration()) / 100000);
} catch (Exception _e) {
}
}
@@ -2850,8 +2797,9 @@ private void _mpCompletionListener() {
obj.setDuration(500);
obj.start();
_customNav(theme_map.get(0).get("colorBackground").toString());
- tmservice._removeFocus();
- tmservice._resetMp();
+ //tmservice._removeFocus();
+ //tmservice._resetMp();
+ zz.clear();
currentlyMap.clear();
currentlyChild.clear();
}
@@ -2864,8 +2812,9 @@ private void _mpCompletionListener() {
}
} else {
if (data.getString("fvsAsc", "").equals("2")) {
- tmservice._mpSeek(0);
- tmservice._mpStart();
+ //tmservice._mpSeek(0);
+ //tmservice._mpStart();
+ zz.requestAction("restart-song");
upload_map = new HashMap<>();
upload_map = currentlyMap.get((int) _position);
upload_map.put("view", String.valueOf((long) (Double.parseDouble(upload_map.get("view").toString()) + 1)));
@@ -2879,9 +2828,9 @@ private void _mpCompletionListener() {
private void _updateTime() {
try {
- if (tmservice._isPlaying()) {
+ if (zz.isPlaying()) {
image_play.setImageResource(R.drawable.ic_pause_white);
- seekbar1.setProgress(tmservice._getCurrentDuration() / 1000);
+ seekbar1.setProgress(zz.getCurrentDuration() / 1000);
} else {
image_play.setImageResource(R.drawable.ic_play_arrow_white);
}
@@ -2901,23 +2850,24 @@ private void _handleMpError(final String _msg) {
obj.setDuration(500);
obj.start();
_customNav(theme_map.get(0).get("colorBackground").toString());
- tmservice._removeFocus();
- tmservice._resetMp();
+ //tmservice._removeFocus();
+ //tmservice._resetMp();
+ zz.requestAction("reset");
currentlyMap.clear();
currentlyChild.clear();
}
private void _bindSvc() {
- if (tmservice == null) {
+ /*if (tmservice == null) {
Intent svcintent = new Intent(StreamerActivity.this, ZryteZeneService.class);
bindService(svcintent, serviceConnection, Context.BIND_AUTO_CREATE);
- }
+ }*/
}
private void _unbindSvc() {
- if (tmservice != null) {
+ /*if (tmservice != null) {
unbindService(serviceConnection);
- }
+ }*/
}
@Deprecated
@@ -4707,7 +4657,7 @@ protected void setResource(Bitmap resource) {
linear_base.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View _view) {
- if (tmservice != null) {
+ //if (tmservice != null) {
currentlyMap.clear();
currentlyChild.clear();
for (int _repeat244 = 0; _repeat244 < upload_list.size(); _repeat244++) {
@@ -4721,7 +4671,7 @@ public void onClick(View _view) {
currentlyChild.add(childkey.get(currentlyChild.size()));
}
_play(currentlyChild.get(_position));
- }
+ //}
}
});
linear_base.setOnLongClickListener(new View.OnLongClickListener() {
@@ -4822,5 +4772,4 @@ public void onClick(DialogInterface _dialog, int _which) {
return _v;
}
}
-
}
diff --git a/app/src/main/java/tw/music/streamer/WizardActivity.java b/app/src/main/java/tw/music/streamer/WizardActivity.java
index 3d9680c..fe638dd 100644
--- a/app/src/main/java/tw/music/streamer/WizardActivity.java
+++ b/app/src/main/java/tw/music/streamer/WizardActivity.java
@@ -10,6 +10,7 @@
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.Typeface;
+import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
@@ -32,7 +33,12 @@
import android.widget.TextView;
import android.widget.Toast;
+import android.Manifest;
+import android.content.pm.PackageManager;
+import android.provider.Settings;
+
import androidx.appcompat.app.AppCompatActivity;
+import androidx.core.app.NotificationManagerCompat;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
@@ -611,10 +617,40 @@ private void _shadow(final View _v, final double _n) {
private void _grantPermission() {
- if (androidx.core.content.ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE) == android.content.pm.PackageManager.PERMISSION_DENIED || androidx.core.content.ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == android.content.pm.PackageManager.PERMISSION_DENIED) {
- androidx.core.app.ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1001);
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ if(checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
+ showMessage("Please allow the notification settings");
+ Intent opd = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
+ opd.putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName());
+ startActivity(opd);
+ } else {
+ if (androidx.core.content.ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE) == android.content.pm.PackageManager.PERMISSION_DENIED || androidx.core.content.ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == android.content.pm.PackageManager.PERMISSION_DENIED) {
+ if (Build.VERSION.SDK_INT < 33) {
+ androidx.core.app.ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1001);
+ } else {
+ _nextSetup();
+ }
+ } else {
+ _nextSetup();
+ }
+ }
} else {
- _nextSetup();
+ if (NotificationManagerCompat.from(WizardActivity.this).areNotificationsEnabled()){
+ if (androidx.core.content.ContextCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE) == android.content.pm.PackageManager.PERMISSION_DENIED || androidx.core.content.ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == android.content.pm.PackageManager.PERMISSION_DENIED) {
+ if (Build.VERSION.SDK_INT < 33) {
+ androidx.core.app.ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1001);
+ } else {
+ _nextSetup();
+ }
+ } else {
+ _nextSetup();
+ }
+ } else {
+ showMessage("Please allow the notification settings");
+ Intent fql = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
+ fql.setData(Uri.parse("package:" + getPackageName()));
+ startActivity(fql);
+ }
}
}
diff --git a/app/src/main/java/tw/music/streamer/ZryteZeneService.java b/app/src/main/java/tw/music/streamer/ZryteZeneService.java
deleted file mode 100644
index 3443e5e..0000000
--- a/app/src/main/java/tw/music/streamer/ZryteZeneService.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package tw.music.streamer;
-
-import android.app.Service;
-import android.content.Intent;
-import android.os.IBinder;
-
-public class ZryteZeneService extends Service {
-
- private ZryteZeneServiceBinder zzServiceBinder = new ZryteZeneServiceBinder();
-
- public ZryteZeneService() {
- }
-
- @Override
- public IBinder onBind(Intent intent) {
- return zzServiceBinder;
- }
-
- @Override
- public boolean onUnbind(Intent intent) {
- zzServiceBinder.stopService();
- return super.onUnbind(intent);
- }
-}
diff --git a/app/src/main/java/tw/music/streamer/ZryteZeneServiceBinder.java b/app/src/main/java/tw/music/streamer/ZryteZeneServiceBinder.java
deleted file mode 100644
index 473970d..0000000
--- a/app/src/main/java/tw/music/streamer/ZryteZeneServiceBinder.java
+++ /dev/null
@@ -1,240 +0,0 @@
-package tw.music.streamer;
-
-import android.content.Context;
-import android.media.AudioManager;
-import android.media.MediaPlayer;
-import android.media.PlaybackParams;
-import android.os.Binder;
-import android.os.Handler;
-import android.os.Message;
-
-public class ZryteZeneServiceBinder extends Binder {
- public String _tmpFour = "";
- public String _tmpFive = "";
- private AudioManager audioManager;
- private AudioManager.OnAudioFocusChangeListener audioListener;
- private MediaPlayer mp;
- private Thread mHandler;
- private Context context;
- private boolean testBool = false;
- private Handler dataHandlerSenderZero;
- private Handler dataHandlerSenderOne;
- private Handler dataHandlerSenderTwo;
- private Handler dataHandlerSenderThree;
- private Handler dataHandlerSenderFour;
- private Handler dataHandlerSenderFive;
-
- public Context getContext() {
- return context;
- }
-
- public void setContext(Context context) {
- this.context = context;
- }
-
- private void sendDataToActivity(int dtype, String data) {
- Message message = new Message();
- message.what = 1;
- if (dtype == 0) {
- dataHandlerSenderZero.sendMessage(message);
- }
- if (dtype == 1) {
- dataHandlerSenderOne.sendMessage(message);
- }
- if (dtype == 2) {
- message.what = (int) Double.parseDouble(data);
- dataHandlerSenderTwo.sendMessage(message);
- }
- if (dtype == 3) {
- dataHandlerSenderThree.sendMessage(message);
- }
- if (dtype == 4) {
- _tmpFour = data;
- dataHandlerSenderFour.sendMessage(message);
- }
- if (dtype == 5) {
- _tmpFive = data;
- dataHandlerSenderFive.sendMessage(message);
- }
- }
-
- public void setDataHandler(Handler dataHandlerSender, int dtype) {
- if (dtype == 0)
- dataHandlerSenderZero = dataHandlerSender;
- if (dtype == 1)
- dataHandlerSenderOne = dataHandlerSender;
- if (dtype == 2)
- dataHandlerSenderTwo = dataHandlerSender;
- if (dtype == 3)
- dataHandlerSenderThree = dataHandlerSender;
- if (dtype == 4)
- dataHandlerSenderFour = dataHandlerSender;
- if (dtype == 5)
- dataHandlerSenderFive = dataHandlerSender;
- }
-
- public void initializeTM() {
- testBool = true;
- mp = null;
- audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
- audioListener = new AudioManager.OnAudioFocusChangeListener() {
- @Override
- public void onAudioFocusChange(int focusState) {
- switch (focusState) {
- case AudioManager.AUDIOFOCUS_GAIN:
- if (mp != null) {
- if (!mp.isPlaying()) {
- mp.start();
- }
- mp.setVolume(1.0f, 1.0f);
- }
- break;
- case AudioManager.AUDIOFOCUS_LOSS:
- if (mp != null) {
- if (mp.isPlaying()) {
- mp.pause();
- }
- }
- break;
- case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
- if (mp != null) {
- if (mp.isPlaying()) {
- mp.pause();
- }
- }
- break;
- case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
- if (mp != null) {
- mp.setVolume(0.1f, 0.1f);
- }
- break;
- }
- }
- };
- mHandler = new Thread() {
- @Override
- public void run() {
- while (true) {
- sendDataToActivity(0, "");
- try {
- Thread.sleep(10);
- } catch (Exception _e) {
- }
- }
- }
- };
- mHandler.start();
- }
-
- public void stopService() {
- if (mHandler != null) {
- mHandler.interrupt();
- mHandler = null;
- }
- }
-
- //some public methods
-
- public int _getCurrentDuration() {
- return mp.getCurrentPosition();
- }
-
- public int _getSongDuration() {
- return mp.getDuration();
- }
-
- public boolean _isPlaying() {
- if (mp != null)
- return mp.isPlaying();
- return false;
- }
-
- public void _mpStart() {
- mp.start();
- }
-
- public void _mpPause() {
- mp.pause();
- }
-
- public boolean _isMpNull() {
- return (mp == null);
- }
-
- public void _mpSeek(int _duration) {
- mp.seekTo(_duration);
- }
-
- public void _resetMp() {
- if (mp != null) {
- if (mp.isPlaying()) {
- mp.stop();
- }
- mp.release();
- mp = null;
- }
- }
-
- public void _requestFocus() {
- int _result = audioManager.requestAudioFocus(audioListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
- if (_result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
- mp.start();
- } else {
- mp.pause();
- }
- }
-
- public void _removeFocus() {
- audioManager.abandonAudioFocus(audioListener);
- }
-
- public void _setNightcore(float _speed) {
- if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
- PlaybackParams params = new PlaybackParams();
- params.setPitch(_speed);
- params.setSpeed(_speed);
- if (mp.isPlaying()) {
- mp.setPlaybackParams(params);
- mp.start();
- } else {
- mp.setPlaybackParams(params);
- mp.pause();
- }
- }
- }
-
- public void _playSongFromURL(String _url) {
- try {
- mp = new MediaPlayer();
- mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
- mp.setDataSource(_url);
- mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
- @Override
- public void onPrepared(MediaPlayer _unmp) {
- sendDataToActivity(1, "");
- mp.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
- @Override
- public void onBufferingUpdate(MediaPlayer _unmp, int _percent) {
- sendDataToActivity(2, String.valueOf((long) _percent));
- }
- });
- mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
- public void onCompletion(MediaPlayer _unmp) {
- sendDataToActivity(3, "");
- }
- });
- }
- });
- mp.setOnErrorListener(new MediaPlayer.OnErrorListener() {
- @Override
- public boolean onError(MediaPlayer _unmp, int _param1, int _param2) {
- sendDataToActivity(4, String.format("Error(%s%s)", _param1, _param2));
- return true;
- }
- });
- mp.prepareAsync();
- } catch (Exception _e) {
- sendDataToActivity(1, _e.toString());
- }
- }
-}
diff --git a/app/src/main/java/tw/music/streamer/adaptor/ZryteZeneAdaptor.java b/app/src/main/java/tw/music/streamer/adaptor/ZryteZeneAdaptor.java
new file mode 100644
index 0000000..611895a
--- /dev/null
+++ b/app/src/main/java/tw/music/streamer/adaptor/ZryteZeneAdaptor.java
@@ -0,0 +1,84 @@
+package tw.music.streamer.adaptor;
+
+import android.content.Intent;
+import android.content.Context;
+
+import java.util.ArrayList;
+
+import tw.music.streamer.service.ZryteZenePlay;
+
+public class ZryteZeneAdaptor {
+
+ private boolean isr, isp;
+ private int cd, bu;
+ private ArrayList e;
+ private Context ctx;
+
+ public ZryteZeneAdaptor(Context a) {
+ isr = false;
+ isp = false;
+ cd = 0;
+ e = new ArrayList<>();
+ ctx = a;
+ }
+
+ public void setRunning(boolean a) {
+ isr = a;
+ }
+
+ public boolean isRunning() {
+ return isr;
+ }
+
+ public void setPlaying(boolean a) {
+ isp = a;
+ }
+
+ public boolean isPlaying() {
+ return isp;
+ }
+
+ public void setCurrentDuration(int a) {
+ cd = a;
+ }
+
+ public int getCurrentDuration() {
+ return cd;
+ }
+
+ public void setBufferingUpdate(int a) {
+ bu = a;
+ }
+
+ public int getBufferingUpdate() {
+ return bu;
+ }
+
+ public void clear() {
+ requestAction("stop","-");
+ }
+
+ public void addError(String a) {
+ e.add(a);
+ }
+
+ public void requestAction(String a) {
+ Intent jof = new Intent(ZryteZenePlay.ACTION_BROADCAST);
+ jof.putExtra("action", a);
+ ctx.sendBroadcast(jof);
+ }
+
+ public void requestAction(String a, int b) {
+ Intent jof = new Intent(ZryteZenePlay.ACTION_BROADCAST);
+ jof.putExtra("action", a);
+ jof.putExtra("req-data", b);
+ ctx.sendBroadcast(jof);
+ }
+
+ public void requestAction(String a, String b) {
+ Intent jof = new Intent(ZryteZenePlay.ACTION_BROADCAST);
+ jof.putExtra("action", a);
+ jof.putExtra("req-data", b);
+ ctx.sendBroadcast(jof);
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/tw/music/streamer/notification/ZryteZeneNotification.java b/app/src/main/java/tw/music/streamer/notification/ZryteZeneNotification.java
new file mode 100644
index 0000000..3a3d62a
--- /dev/null
+++ b/app/src/main/java/tw/music/streamer/notification/ZryteZeneNotification.java
@@ -0,0 +1,73 @@
+package tw.music.streamer.notification;
+
+import android.os.Build;
+import android.app.Notification;
+import android.app.PendingIntent;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Intent;
+import android.content.Context;
+
+import tw.music.streamer.service.ZryteZenePlay;
+import tw.music.streamer.StreamerActivity;
+
+public class ZryteZeneNotification {
+
+ public static Notification setup(Context a) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ NotificationChannel ch = new NotificationChannel(
+ ZryteZenePlay.CHANNEL_ID,
+ "Music Playback",
+ NotificationManager.IMPORTANCE_HIGH
+ );
+ ch.setSound(null, null);
+ ch.enableLights(false);
+ ch.enableVibration(false);
+ NotificationManager mr = a.getSystemService(NotificationManager.class);
+ if (mr != null) {
+ mr.createNotificationChannel(ch);
+ }
+ }
+
+ Intent openAppIntent = new Intent(a, StreamerActivity.class);
+ PendingIntent openAppPendingIntent = PendingIntent.getActivity(a, 0, openAppIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
+
+ Notification notification = new Notification.Builder(a, ZryteZenePlay.CHANNEL_ID)
+ .setContentTitle("ZryteZene")
+ .setContentText("Idle...")
+ .setSmallIcon(android.R.drawable.ic_media_play)
+ .setContentIntent(openAppPendingIntent)
+ .setOnlyAlertOnce(true)
+ .build();
+ return notification;
+ }
+
+ public static void update(Context a, String b) {
+ Intent openAppIntent = new Intent(a, StreamerActivity.class);
+ PendingIntent openAppPendingIntent = PendingIntent.getActivity(a, 0, openAppIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
+ NotificationManager notificationManager = (NotificationManager) a.getSystemService(Context.NOTIFICATION_SERVICE);
+ if (notificationManager == null) return;
+ Notification notification;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ notification = new Notification.Builder(a, ZryteZenePlay.CHANNEL_ID)
+ .setContentTitle("ZryteZene")
+ .setContentText(b)
+ .setSmallIcon(android.R.drawable.ic_media_play)
+ .setContentIntent(openAppPendingIntent)
+ .setOngoing(true)
+ .setOnlyAlertOnce(true)
+ .build();
+ } else {
+ notification = new Notification.Builder(a)
+ .setContentTitle("ZryteZene")
+ .setContentText(b)
+ .setSmallIcon(android.R.drawable.ic_media_pause)
+ .setContentIntent(openAppPendingIntent)
+ .setOngoing(true)
+ .setOnlyAlertOnce(true)
+ .build();
+ }
+ notificationManager.notify(ZryteZenePlay.NOTIFICATION_ID, notification);
+ }
+
+}
diff --git a/app/src/main/java/tw/music/streamer/service/ZryteZenePlay.java b/app/src/main/java/tw/music/streamer/service/ZryteZenePlay.java
new file mode 100644
index 0000000..f560bf4
--- /dev/null
+++ b/app/src/main/java/tw/music/streamer/service/ZryteZenePlay.java
@@ -0,0 +1,276 @@
+package tw.music.streamer.service;
+
+import android.os.Build;
+import android.os.Handler;
+import android.os.IBinder;
+import android.util.Log;
+import android.app.Service;
+import android.app.Activity;
+import android.app.NotificationManager;
+import android.media.MediaPlayer;
+import android.media.AudioManager;
+import android.content.Intent;
+import android.content.Context;
+import android.content.IntentFilter;
+import android.content.BroadcastReceiver;
+import android.content.SharedPreferences;
+
+import androidx.annotation.Nullable;
+
+import tw.music.streamer.notification.ZryteZeneNotification;
+
+public class ZryteZenePlay extends Service implements MediaPlayer.OnPreparedListener, MediaPlayer.OnBufferingUpdateListener, MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener {
+
+ public static final String ACTION_BROADCAST = "tw.music.streamer.ACTION";
+ public static final String ACTION_UPDATE = "tw.music.streamer.ACTION_UPDATE";
+
+ public static final String CHANNEL_ID = "music_channel";
+ public static final int NOTIFICATION_ID = 2;
+
+ private BroadcastReceiver br;
+ private MediaPlayer mp;
+ private IntentFilter ief;
+ private SharedPreferences sp;
+ private String lm, act, csp;
+ private Intent ita;
+ private Handler ha = new Handler();
+ private boolean pd = false;
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ initializePlayer();
+ }
+
+ @Override
+ public int onStartCommand(Intent a, int b, int c) {
+ if (ief == null) initializePlayer();
+ if (a != null) onReceived(a);
+ return START_STICKY;
+ }
+
+ @Override
+ public void onDestroy() {
+ unregisterReceiver(br);
+ if (mp!=null) {
+ mp.release();
+ mp = null;
+ }
+ super.onDestroy();
+ }
+
+ @Nullable
+ @Override
+ public IBinder onBind(Intent a) {
+ return null;
+ }
+
+ private Runnable pr = new Runnable() {
+ @Override
+ public void run() {
+ if (mp != null) {
+ if (mp.isPlaying()) tellActivity("on-tick", mp.getCurrentPosition());
+ ha.postDelayed(this, 500);
+ }
+ }
+ };
+
+
+ private void initializePlayer() {
+ startForeground(NOTIFICATION_ID, ZryteZeneNotification.setup(getApplicationContext()));
+ sp = getSharedPreferences("teamdata", Activity.MODE_PRIVATE);
+ lm = sp.getString("fvsAsc", "");
+ mp = new MediaPlayer();
+ br = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context a, Intent b) {
+ if (b != null) onReceived(a,b);
+ }
+ };
+ ief = new IntentFilter(ACTION_BROADCAST);
+ registerReceiver(br, ief);
+ applyMediaListener();
+ tellActivity("Initialization completed");
+ }
+
+ @Override
+ public void onPrepared(MediaPlayer a) {
+ a.start();
+ pd = true;
+ ZryteZeneNotification.update(getApplicationContext(), "Playing music...");
+ tellActivity("on-prepared",a.getDuration());
+ ha.post(pr);
+ }
+
+ @Override
+ public void onBufferingUpdate(MediaPlayer a, int b) {
+ tellActivity("on-bufferupdate",b);
+ }
+
+ @Override
+ public void onCompletion(MediaPlayer a) {
+ ZryteZeneNotification.update(getApplicationContext(), "Idle...");
+ tellActivity("on-completion","1");
+ }
+
+ @Override
+ public boolean onError(MediaPlayer a, int b, int c) {
+ ZryteZeneNotification.update(getApplicationContext(), "Idle...");
+ tellActivity("on-error", String.format("Error(%s%s)", b, c));
+ return true;
+ }
+
+ private void onReceived(Intent a) {
+ onReceived(getApplicationContext(), a);
+ }
+
+ private void onReceived(Context a, Intent b) {
+ if (b.getAction() == null) return;
+ if (!b.getAction().equals(ACTION_BROADCAST)) return;
+ if (!b.hasExtra("action")) return;
+ act = b.getStringExtra("action");
+ if (act.equals("seek")) {
+ seekSong(b);
+ } else if (act.equals("play")) {
+ playSong(b);
+ } else if (act.equals("pause")) {
+ pauseSong();
+ } else if (act.equals("resume")) {
+ resumeSong();
+ } else if (act.equals("stop")) {
+ stopSong();
+ } else if (act.equals("update-sp")) {
+ updateSP(b);
+ } else if (act.equals("restart-song")) {
+ restartSong();
+ } else if (act.equals("reset")) {
+ resetMedia();
+ } else if (act.equals("request-media")) {
+ requestMedia();
+ }
+ }
+
+ private void applyMediaListener() {
+ mp.setOnPreparedListener(this);
+ mp.setOnBufferingUpdateListener(this);
+ mp.setOnCompletionListener(this);
+ mp.setOnErrorListener(this);
+ }
+
+ private void playSong(Intent a) {
+ csp = a.getStringExtra("req-data");
+ if (mp != null) {
+ mp.reset();
+ } else {
+ mp = new MediaPlayer();
+ mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
+ applyMediaListener();
+ }
+ try {
+ mp.setDataSource(csp);
+ mp.prepareAsync();
+ tellActivity("request-play");
+ } catch (Exception e) {
+ tellActivity("on-error", e.toString());
+ }
+ }
+
+ private void pauseSong() {
+ if (mp==null) return;
+ if (mp.isPlaying()) {
+ mp.pause();
+ ZryteZeneNotification.update(getApplicationContext(), "Music paused");
+ tellActivity("request-pause");
+ }
+ }
+
+ private void resumeSong() {
+ if (mp==null) return;
+ if (isPrepared() && !mp.isPlaying()) {
+ mp.start();
+ ZryteZeneNotification.update(getApplicationContext(), "Playing music...");
+ tellActivity("request-resume");
+ }
+ }
+
+ private void stopSong() {
+ if (mp==null) return;
+ if (mp.isPlaying()) {
+ mp.stop();
+ NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+ if (notificationManager != null) {
+ notificationManager.cancel(NOTIFICATION_ID);
+ }
+ ha.removeCallbacks(pr);
+ tellActivity("request-stop");
+ }
+ }
+
+ private void seekSong(Intent a) {
+ if (mp==null) return;
+ if (isPrepared()) {
+ int b = a.getIntExtra("req-data",0);
+ if (b > mp.getDuration()) return;
+ mp.seekTo(b);
+ tellActivity("request-seek", b);
+ } else {
+ tellActivity("on-seekerror");
+ }
+ }
+
+ private void restartSong() {
+ if (mp==null) return;
+ if (!isPrepared()) return;
+ if (mp.isPlaying()) mp.stop();
+ mp.seekTo(0);
+ mp.start();
+ tellActivity("request-restart");
+ }
+
+ private void resetMedia() {
+ mp = new MediaPlayer();
+ tellActivity("request-reset");
+ }
+
+ private void tellActivity(String a) {
+ ita = new Intent(ACTION_UPDATE);
+ ita.putExtra("update", a);
+ sendBroadcast(ita);
+ }
+
+ private void tellActivity(String a, String b) {
+ ita = new Intent(ACTION_UPDATE);
+ ita.putExtra("update", a);
+ ita.putExtra("data", b);
+ sendBroadcast(ita);
+ }
+
+ private void tellActivity(String a, int b) {
+ ita = new Intent(ACTION_UPDATE);
+ ita.putExtra("update", a);
+ ita.putExtra("data", b);
+ sendBroadcast(ita);
+ }
+
+ private void updateSP(Intent a) {
+ String b = a.getStringExtra("req-data");
+ if (b.equals("loop")) {
+ lm = sp.getString("fvsAsc", "");
+ }
+ }
+
+ private void requestMedia() {
+ ita = new Intent(ACTION_UPDATE);
+ ita.putExtra("update", "on-reqmedia");
+ ita.putExtra("status", mp == null ? 0 : mp.isPlaying() ? 1 : isPrepared() ? 2 : 0);
+ if (mp != null && isPrepared()) {
+ ita.putExtra("duration", mp.getDuration());
+ ita.putExtra("currentDuration", mp.getCurrentPosition());
+ }
+ sendBroadcast(ita);
+ }
+
+ private boolean isPrepared() {
+ return pd;
+ }
+}
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index 1fa1c3a..8be385e 100644
--- a/build.gradle
+++ b/build.gradle
@@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
- classpath 'com.android.tools.build:gradle:4.0.1'
+ classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.google.gms:google-services:4.3.3'
// NOTE: Do not place your application dependencies here; they belong
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index e80cf30..e11d298 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip