Modified:
trunk/src/android/AndroidManifest.xml
trunk/src/android/src/org/musikcube/Service.java
trunk/src/android/src/org/musikcube/TrackList.java
trunk/src/android/src/org/musikcube/core/Library.java
Log:
Started on android Service for playback.
Modified: trunk/src/android/AndroidManifest.xml
==============================================================================
--- trunk/src/android/AndroidManifest.xml (original)
+++ trunk/src/android/AndroidManifest.xml Fri Jul 10 08:10:19 2009
@@ -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>
Modified: trunk/src/android/src/org/musikcube/Service.java
==============================================================================
--- trunk/src/android/src/org/musikcube/Service.java (original)
+++ trunk/src/android/src/org/musikcube/Service.java Fri Jul 10 08:10:19
2009
@@ -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 @@
*/
public class Service extends android.app.Service {
+ Library library;
+ MediaPlayer player;
+
+ ArrayList<Integer> nowPlaying = new ArrayList<Integer>();
+ int nowPlayingPosition = 0;
/**
*
@@ -31,8 +43,47 @@
@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();
+ }
+ }
+ }
+
+
}
Modified: trunk/src/android/src/org/musikcube/TrackList.java
==============================================================================
--- trunk/src/android/src/org/musikcube/TrackList.java (original)
+++ trunk/src/android/src/org/musikcube/TrackList.java Fri Jul 10 08:10:19
2009
@@ -155,6 +155,12 @@
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);
+
}
}
Modified: trunk/src/android/src/org/musikcube/core/Library.java
==============================================================================
--- trunk/src/android/src/org/musikcube/core/Library.java (original)
+++ trunk/src/android/src/org/musikcube/core/Library.java Fri Jul 10
08:10:19 2009
@@ -19,15 +19,17 @@
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 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;
+ }
+ }
+
+ public void WaitForAuthroization(){
+ Log.v("Library::WaitForAuthroization","start");
+ synchronized (notifier) {
+ if(this.authorization.equals("")){
+ try {
+ notifier.wait();
+ } catch (InterruptedException e) {
+ }
+ }
}
- return false;
+ Log.v("Library::WaitForAuthroization","end");
}
public void run(){
@@ -97,9 +115,14 @@
//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");
+ }
}
}