implement ugly ghost-path detector

This commit is contained in:
Adrian Ulrich 2013-01-15 18:07:31 +01:00
parent 76cfe8e680
commit e59782e54e
4 changed files with 46 additions and 4 deletions

View File

@ -19,7 +19,7 @@ function show(n) {
</head>
<body>
<h1>Vanilla Music</h1>
<p><b>Version:</b> 0.9.15 released November 10, 2012<br><br>
<p><b>Version:</b> 0.9.16 released December 14, 2012<br><br>
<b>Website:</b> <a href='https://github.com/adrian-bl/vanilla'>https://github.com/adrian-bl/vanilla</a><br>
<b>Issue tracker:</b> <a href='https://github.com/adrian-bl/vanilla/issues'>https://github.com/adrian-bl/vanilla/issues</a><br>
<h2>Contributors</h2>

View File

@ -235,4 +235,6 @@ THE SOFTWARE.
<string name="show_queue">Show queue</string>
<string name="queue">Queue</string>
<string name="toggle_controls">Toggle controls</string>
<string name="filebrowser_start">TRNS! FP Start</string>
<string name="customize_filebrowser_start">Browsing files starts at this directory</string>
</resources>

View File

@ -34,6 +34,8 @@ import java.util.Collections;
import java.util.List;
import java.util.Random;
import junit.framework.Assert;
import android.os.Environment;
import android.util.Log;
/**
* Provides some static Song/MediaStore-related utility functions.
@ -512,6 +514,43 @@ public class MediaUtils {
return file.delete();
}
/**
* This is an ugly hack: The tries to 'guess' if given path
* is also accessible using a fuse mount
*/
private static String sanitizeMediaPath(String path) {
Log.v("Vanilla", "Input path is: "+path);
String exPath = Environment.getExternalStorageDirectory().getAbsolutePath();
File exStorage = new File(exPath+"/Android");
long exLastmod = exStorage.lastModified();
if(exLastmod != 0) {
String pfx = path;
while(true) {
if((new File(pfx+"/Android")).lastModified() == exLastmod) {
String guessPath = exPath + path.substring(pfx.length());
if( (new File(guessPath)).exists() ) {
Log.v("Vanilla", "OLD="+path);
Log.v("Vanilla", "NEW="+guessPath);
path = guessPath;
break;
}
}
pfx = (new File(pfx)).getParent();
if(pfx == null)
break; /* hit root */
}
}
Log.v("Vanilla", "Returning "+path);
return path;
}
/**
* Build a query that will contain all the media under the given path.
*
@ -523,9 +562,10 @@ public class MediaUtils {
{
// It would be better to use selectionArgs to pass path here, but there
// doesn't appear to be any way to pass the * when using it.
Log.v("Vanilla", "buildFileQuery "+path);
StringBuilder selection = new StringBuilder();
selection.append("_data GLOB ");
DatabaseUtils.appendEscapedSQLString(selection, path);
DatabaseUtils.appendEscapedSQLString(selection, sanitizeMediaPath(path));
// delete the quotation mark added by the escape method
selection.deleteCharAt(selection.length() - 1);
selection.append("*' AND is_music");

View File

@ -562,7 +562,7 @@ public final class PlaybackService extends Service
public void prepareMediaPlayer(MediaPlayer mp, String path) throws IOException{
mp.setDataSource(path);
/*
Hashtable tags = (new Bastp()).getTags(path);
float adjust = 1.0f;
@ -577,10 +577,10 @@ public final class PlaybackService extends Service
adjust = (float)Math.pow(10, (rg_float/20) );
Toast.makeText(this, path+"\n"+" PX "+rg_raw+" adj = "+adjust, Toast.LENGTH_LONG).show();
}
mp.setVolume(adjust, adjust);
*/
mp.prepare();
}