mirror of
https://github.com/clangen/musikcube.git
synced 2024-11-19 11:10:52 +00:00
Started on android Service for playback.
This commit is contained in:
parent
8176e04392
commit
d5da9d8d67
@ -11,7 +11,7 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<service android:name="Service" android:enabled="false" android:process=":remote"></service>
|
||||
<service android:name="Service" android:process=":remote" android:enabled="true"></service>
|
||||
<activity android:name="CategoryList"></activity>
|
||||
<activity android:name="TrackList"></activity>
|
||||
</application>
|
||||
|
@ -3,8 +3,15 @@
|
||||
*/
|
||||
package org.musikcube;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.musikcube.core.Library;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* @author doy
|
||||
@ -12,6 +19,11 @@ import android.os.IBinder;
|
||||
*/
|
||||
public class Service extends android.app.Service {
|
||||
|
||||
Library library;
|
||||
MediaPlayer player;
|
||||
|
||||
ArrayList<Integer> nowPlaying = new ArrayList<Integer>();
|
||||
int nowPlayingPosition = 0;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -31,8 +43,47 @@ public class Service extends android.app.Service {
|
||||
|
||||
@Override
|
||||
public void onCreate(){
|
||||
org.musikcube.core.Library library = org.musikcube.core.Library.GetInstance();
|
||||
Log.i("musikcube::Service","CREATE");
|
||||
this.library = org.musikcube.core.Library.GetInstance();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.app.Service#onStart(android.content.Intent, int)
|
||||
*/
|
||||
@Override
|
||||
public void onStart(Intent intent, int startId) {
|
||||
// TODO Auto-generated method stub
|
||||
super.onStart(intent, startId);
|
||||
|
||||
if(intent.getIntegerArrayListExtra("org.musikcube.Service.tracklist")!=null){
|
||||
|
||||
this.nowPlaying = intent.getIntegerArrayListExtra("org.musikcube.Service.tracklist");
|
||||
this.nowPlayingPosition = intent.getIntExtra("org.musikcube.Service.position", 0);
|
||||
|
||||
Log.i("musikcube::Service","onStart "+this.nowPlaying.size());
|
||||
|
||||
if(this.player==null){
|
||||
this.player = new MediaPlayer();
|
||||
}
|
||||
|
||||
Log.i("musikcube::Service","onStart2 "+(this.player!=null));
|
||||
this.library.WaitForAuthroization();
|
||||
|
||||
try {
|
||||
Log.i("musikcube::Service","onStart3 "+"http://"+this.library.host+":"+this.library.httpPort+"/track/?track_id="+this.nowPlaying.get(this.nowPlayingPosition)+"&auth_key="+this.library.authorization);
|
||||
this.player.setDataSource("http://"+this.library.host+":"+this.library.httpPort+"/track/?track_id="+this.nowPlaying.get(this.nowPlayingPosition)+"&auth_key="+this.library.authorization);
|
||||
Log.i("musikcube::Service","onStart4");
|
||||
this.player.prepare();
|
||||
Log.i("musikcube::Service","onStart5");
|
||||
this.player.start();
|
||||
Log.i("musikcube::Service","onStart6");
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -155,6 +155,12 @@ public class TrackList extends ListActivity implements OnQueryResultListener {
|
||||
intent.putExtra("org.musikcube.CategoryList.selectedCategoryId", (int)id);
|
||||
startActivity(intent);
|
||||
}*/
|
||||
|
||||
Intent intent = new Intent(this, org.musikcube.Service.class);
|
||||
intent.putExtra("org.musikcube.Service.tracklist", this.query.trackList);
|
||||
intent.putExtra("org.musikcube.Service.position", position);
|
||||
startService(intent);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,15 +19,17 @@ public class Library implements Runnable{
|
||||
|
||||
private String username;
|
||||
private String password;
|
||||
private String authorization;
|
||||
private String host;
|
||||
public String authorization = "";
|
||||
public String host;
|
||||
private int queryPort;
|
||||
private int httpPort;
|
||||
public int httpPort;
|
||||
|
||||
private Thread thread;
|
||||
private boolean running = false;
|
||||
private Socket socket;
|
||||
|
||||
private java.lang.Object notifier = new java.lang.Object();
|
||||
|
||||
private java.util.LinkedList<IQuery> sendQueryQueue = new java.util.LinkedList<IQuery>();
|
||||
private java.util.LinkedList<IQuery> waitingQueryQueue = new java.util.LinkedList<IQuery>();
|
||||
|
||||
@ -65,21 +67,37 @@ public class Library implements Runnable{
|
||||
|
||||
public boolean Connect(String host,String username,String password,int queryPort,int httpPort){
|
||||
//Log.i("Library","starting "+host+":"+queryPort);
|
||||
if(!running){
|
||||
this.host = host;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.queryPort = queryPort;
|
||||
this.httpPort = httpPort;
|
||||
|
||||
// Startup thread
|
||||
this.thread = new Thread(this);
|
||||
// this.thread.setDaemon(true);
|
||||
this.running = true;
|
||||
this.thread.start();
|
||||
return true;
|
||||
synchronized (notifier) {
|
||||
|
||||
if(!running){
|
||||
this.host = host;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.queryPort = queryPort;
|
||||
this.httpPort = httpPort;
|
||||
|
||||
// Startup thread
|
||||
this.thread = new Thread(this);
|
||||
// this.thread.setDaemon(true);
|
||||
this.running = true;
|
||||
this.thread.start();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void WaitForAuthroization(){
|
||||
Log.v("Library::WaitForAuthroization","start");
|
||||
synchronized (notifier) {
|
||||
if(this.authorization.equals("")){
|
||||
try {
|
||||
notifier.wait();
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
Log.v("Library::WaitForAuthroization","end");
|
||||
}
|
||||
|
||||
public void run(){
|
||||
@ -97,9 +115,14 @@ public class Library implements Runnable{
|
||||
//Log.v("Library::run","Authtag found");
|
||||
// Wait for authorization tag to end
|
||||
authNode.End();
|
||||
//Log.v("Library::run","Authtag end");
|
||||
this.authorization = authNode.content;
|
||||
//Log.v("Library::run","Authorization="+this.authorization);
|
||||
|
||||
synchronized (notifier) {
|
||||
Log.v("Library::run","Authtag end");
|
||||
this.authorization = authNode.content;
|
||||
Log.v("Library::run","Authorization="+this.authorization);
|
||||
this.notifier.notifyAll();
|
||||
Log.v("Library::run","Authorization notify");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user