Skip to content

Commit

Permalink
fixes + search enhancement + equalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
deep-gaurav committed Jun 16, 2019
1 parent c914bee commit 584549f
Show file tree
Hide file tree
Showing 10 changed files with 586 additions and 181 deletions.
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ android {
applicationId "deep.ryd.rydplayer"
minSdkVersion 21
targetSdkVersion 28
versionCode 53
versionName "2.0.3"
versionCode 54
versionName "2.0.4"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
Expand Down
67 changes: 55 additions & 12 deletions android/app/src/main/java/deep/ryd/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.media.AudioManager;
import android.media.MediaMetadata;
import android.media.MediaPlayer;
import android.media.audiofx.AudioEffect;
import android.media.session.MediaSession;
import android.media.session.PlaybackState;
import android.net.Uri;
Expand All @@ -32,6 +33,7 @@
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.services.youtube.YoutubeService;
import org.schabi.newpipe.extractor.stream.AudioStream;
import org.schabi.newpipe.extractor.stream.StreamExtractor;
import org.schabi.newpipe.extractor.stream.StreamInfo;
import org.schabi.newpipe.extractor.utils.Localization;
Expand All @@ -41,7 +43,9 @@
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

Expand All @@ -54,6 +58,9 @@
import okhttp3.RequestBody;
import okhttp3.Response;

import static android.media.audiofx.AudioEffect.CONTENT_TYPE_MUSIC;
import static android.media.audiofx.AudioEffect.EXTRA_CONTENT_TYPE;


enum PlayerState{
Playing,Paused,Loading,Idle
Expand Down Expand Up @@ -210,6 +217,8 @@ public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
Log.d("musicpiped", "androidcached " + cached);
} else if(methodCall.method.equals("readyOpenURL")){
result.success(openURL);
} else if(methodCall.method.equals("openSystemEqualizer")){
openAudioFx();
}

else {
Expand Down Expand Up @@ -280,7 +289,7 @@ public void onCompletion(MediaPlayer mp) {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
//methodChannel.invokeMethod("error","");
Log.i("musicpiped", "MediPlayer Error : " + what + " " + extra);
//Log.i("musicpiped", "MediPlayer Error : " + what + " " + extra);
if (extra == MediaPlayer.MEDIA_ERROR_IO || extra == MediaPlayer.MEDIA_ERROR_TIMED_OUT) {
Log.d("musicpiped", "Timeout");
next();
Expand All @@ -296,6 +305,34 @@ public boolean onError(MediaPlayer mp, int what, int extra) {
handleURL(appLinkIntent);

}
public void openAudioFx() {
try{

Intent i = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, UMP.getAudioSessionId());

startActivityForResult(i,0);
}
catch (Exception e){
e.printStackTrace();
}
}

public void applyAudioFx(){
try{

Intent i = new Intent(AudioEffect.ACTION_DISPLAY_AUDIO_EFFECT_CONTROL_PANEL);
i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, UMP.getAudioSessionId());

startActivityForResult(i,0);
}
catch (Exception e){
e.printStackTrace();
}
}


void handleURL(Intent appLinkIntent){
String appLinkAction = appLinkIntent.getAction();
Expand Down Expand Up @@ -696,7 +733,7 @@ class URLVerifier extends AsyncTask<String,String,String>{
this.videoId=videoId;
}

String getNewpipeURL() throws ExtractionException, IOException {
List<String> getNewpipeURL() throws ExtractionException, IOException {

Log.d("musicpiped","Get newpipe URL");

Expand All @@ -707,14 +744,11 @@ String getNewpipeURL() throws ExtractionException, IOException {
YoutubeService youtubeService = (YoutubeService) NewPipe.getService(NewPipe.getIdOfService("YouTube"));
StreamExtractor streamExtractor = youtubeService.getStreamExtractor(url);
streamExtractor.fetchPage();
if(streamExtractor.getAudioStreams().size()>1)
return streamExtractor.getAudioStreams().get(0).url;
else if(streamExtractor.getVideoStreams().size()>1){
return streamExtractor.getVideoStreams().get(0).url;
}
else {
return "ERROR";
List<String> urls = new ArrayList<>();
for(AudioStream s: streamExtractor.getAudioStreams()){
urls.add(s.url);
}
return urls;
}

boolean verifyURL (String url){
Expand Down Expand Up @@ -748,23 +782,32 @@ protected String doInBackground(String... strings) {
String url = strings[0];

Log.d("musicpiped","CheckResponseCode");
while (verifyURL(url)){
for(int tries=0;tries<3 && verifyURL(url); tries++){
try {
url = getNewpipeURL();
List<String> newURLS = getNewpipeURL();
for(String newurl : newURLS){
if(!verifyURL(newurl)){
url = newurl;
break;
}
}
} catch (ExtractionException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
if(verifyURL(url)){
url = "ERROR";
}
return url;
}

@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
if(s=="ERROR"){
Toast.makeText(activity,"Can not play that track, Retry late",Toast.LENGTH_LONG);
Toast.makeText(activity,"Can not play that track, Retry later",Toast.LENGTH_LONG).show();
activity.next();
}else{
try {
Expand Down
2 changes: 2 additions & 0 deletions android/app/src/main/java/deep/ryd/URLProxyFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public static HttpProxyCacheServer getProxy(Context context) {
private static HttpProxyCacheServer newProxy(Context context) {
return new HttpProxyCacheServer.Builder(context)
.fileNameGenerator(new TrackFileNameGenerator())
.maxCacheFilesCount(50)
.maxCacheSize(1024 * 1024 * 500)
.build();
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ class Library extends StatelessWidget {
child: Card(
child: ListTile(
title: Text(p['title']),
trailing: p.containsKey('playlistId') ? Icon(Icons.sync) : null,
trailing: p.containsKey('playlistId') || p.containsKey('mixId') ? Icon(Icons.sync) : null,
onTap: () {
if (p.containsKey('playlistId')) {
if (p.containsKey('playlistId') || p.containsKey('mixId')) {
Navigator.push(
context,
MaterialPageRoute(
Expand Down
Loading

0 comments on commit 584549f

Please sign in to comment.