1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
package com.example.sma.musicforrun;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import com.echonest.api.v4.EchoNestAPI;
import com.echonest.api.v4.EchoNestException;
import com.echonest.api.v4.Track;
import java.io.File;
import java.io.IOException;
public class MainActivity extends ActionBarActivity {
TextView textbpm;
TextView titre;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
double bpm=0;
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if(networkInfo != null && networkInfo.isAvailable() && networkInfo.isConnected()) {
boolean wifi = networkInfo.getType() == ConnectivityManager.TYPE_WIFI;
Log.d("NetworkState", "Interface connexion wifi : " + wifi);
}
try{
bpm = calculbpm();
}catch(EchoNestException e){
System.err.println("Trouble with EchoNestException");
}
String bpm2 = String.valueOf(bpm);
textbpm = (TextView)findViewById(R.id.txtbpm);
textbpm.setText(bpm2);
}
public double calculbpm () throws EchoNestException {
double bpm =0;
EchoNestAPI en = new EchoNestAPI("IZXIFD2IFPOZX5X9C");
String path = "/storage/extSdCard/113 - Partir Loin.mp3";
titre = (TextView)findViewById(R.id.titre);
File file = new File(path);
if (!file.exists()) {
System.err.println("Can't find " + path);
titre.setText("Can't find" + path);
} else {
try {
System.out.println("Upload Track, please wait ...");
titre.setText("Upload Track, please wait ...");
Track track = en.uploadTrack(file, false);
titre.setText("End of upload!");
track.waitForAnalysis(30000);
System.out.println("End of upload!");
titre.setText("End of upload!");
if (track.getStatus() == Track.AnalysisStatus.COMPLETE) {
System.out.println("Tempo: " + track.getTempo());
bpm = track.getTempo();
} else {
System.err.println("Trouble analysing track " + track.getStatus());
}
} catch (IOException e) { //IOException e
System.err.println("Trouble uploading file");
}
}
return bpm;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
} |
Partager