mirror of
https://github.com/clangen/musikcube.git
synced 2024-10-02 04:52:32 +00:00
Loading track metadata in tracklist.
This commit is contained in:
parent
98a54c6a9a
commit
e9e9a0b79b
@ -5,7 +5,7 @@
|
||||
android:versionName="1.0">
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name" android:name="App">
|
||||
<activity android:name=".main"
|
||||
android:label="@string/app_name">
|
||||
android:label="@string/app_name" android:launchMode="singleTask">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
@ -15,7 +15,7 @@
|
||||
<activity android:name="CategoryList"></activity>
|
||||
<activity android:name="TrackList"></activity>
|
||||
<activity android:name="Preferences"></activity>
|
||||
<activity android:name="PlayerControl"></activity>
|
||||
<activity android:name="PlayerControl" android:launchMode="singleTask"></activity>
|
||||
</application>
|
||||
<uses-sdk android:minSdkVersion="3" />
|
||||
|
||||
@ -23,4 +23,5 @@
|
||||
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
||||
|
||||
|
||||
|
||||
</manifest>
|
@ -4,9 +4,18 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
|
||||
<LinearLayout android:id="@+id/LinearLayout01" android:orientation="horizontal" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="0.5"><ImageButton android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="0.5" android:layout_margin="5px" android:id="@+id/GenresButton" android:src="@drawable/genres" android:clickable="true"></ImageButton><ImageButton android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="0.5" android:layout_margin="5px" android:id="@+id/ArtistsButton"></ImageButton></LinearLayout>
|
||||
<LinearLayout android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="fill_parent" android:padding="4sp" android:layout_weight="0.1">
|
||||
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon"></ImageView>
|
||||
<TextView android:layout_height="wrap_content" android:text="musikCube" android:layout_width="wrap_content" android:textSize="22sp" android:padding="4sp"></TextView>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout android:id="@+id/LinearLayout02" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="0.5"><ImageButton android:id="@+id/ImageButton01" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="0.5" android:layout_margin="5px"></ImageButton><ImageButton android:id="@+id/ImageButton01" android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_weight="0.5" android:layout_margin="5px"></ImageButton></LinearLayout>
|
||||
<LinearLayout android:orientation="vertical" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="0.8">
|
||||
<TextView android:id="@+id/TextView01" android:layout_height="wrap_content" android:text="Browse by:" android:layout_width="fill_parent" android:background="@color/headlineColor" android:textSize="16sp" android:padding="4sp"></TextView>
|
||||
<Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:textSize="22sp" android:text="Genre" android:id="@+id/GenresButton"></Button>
|
||||
<Button android:layout_height="wrap_content" android:layout_width="fill_parent" android:textSize="22sp" android:id="@+id/ArtistsButton" android:text="Artist"></Button>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView android:id="@+id/StatusView" android:text="Status: -" android:layout_width="fill_parent" android:background="@color/headlineColor" android:textSize="16sp" android:padding="4sp" android:layout_height="wrap_content" android:layout_gravity="bottom" android:layout_weight="0.1"></TextView>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
@ -7,7 +7,7 @@
|
||||
android:paddingRight="8dp" android:gravity="center_vertical|center_horizontal">
|
||||
|
||||
<LinearLayout android:id="@+id/LinearLayout01" android:layout_weight="0.5" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="left">
|
||||
<ImageView android:id="@+id/ImageView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/album" android:layout_marginTop="5sp" android:layout_marginBottom="5sp"></ImageView>
|
||||
<ImageView android:id="@+id/ImageView01" android:layout_width="wrap_content" android:src="@drawable/album" android:layout_marginTop="5sp" android:layout_marginBottom="5sp" android:layout_height="wrap_content"></ImageView>
|
||||
<TextView android:id="@+id/TextView04" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Track" android:textSize="24sp"></TextView>
|
||||
<TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Genre:"></TextView>
|
||||
<TextView android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Album:"></TextView>
|
||||
@ -22,4 +22,5 @@
|
||||
|
||||
|
||||
|
||||
<SeekBar android:id="@+id/SeekBar01" android:layout_height="wrap_content" android:layout_width="fill_parent" android:max="1000" android:progress="300" android:secondaryProgress="100"></SeekBar>
|
||||
</LinearLayout>
|
@ -15,4 +15,5 @@
|
||||
<string name="password">doep</string>
|
||||
<string name="queryport">10543</string>
|
||||
<string name="httpport">10544</string>
|
||||
<color name="headlineColor">#333333</color>
|
||||
</resources>
|
||||
|
@ -2,13 +2,13 @@
|
||||
|
||||
|
||||
<PreferenceCategory android:title="Connection">
|
||||
<EditTextPreference android:key="@string/host" android:enabled="true" android:title="Host" android:dialogMessage="Hostname or IP to musikServer" android:summary="Hostname or IP to musikServer" android:dialogTitle="Host" android:selectable="true" android:defaultValue="vallgraven.intermezzon.com"></EditTextPreference>
|
||||
<EditTextPreference android:key="@string/queryport" android:enabled="true" android:inputType="number" android:title="Query port" android:dialogMessage="TCP port for querying musikServer" android:summary="TCP port for querying musikServer" android:dialogTitle="Query port" android:defaultValue="10543"></EditTextPreference>
|
||||
<EditTextPreference android:key="@string/httpport" android:enabled="true" android:inputType="number" android:title="HTTP port" android:dialogMessage="TCP port for streaming music" android:summary="TCP port for streaming music" android:dialogTitle="HTTP port" android:defaultValue="10544"></EditTextPreference>
|
||||
<EditTextPreference android:key="host" android:enabled="true" android:title="Host" android:dialogMessage="Hostname or IP to musikServer" android:summary="Hostname or IP to musikServer" android:dialogTitle="Host" android:selectable="true" android:defaultValue="vallgraven.intermezzon.com"></EditTextPreference>
|
||||
<EditTextPreference android:key="queryport" android:enabled="true" android:inputType="number" android:title="Query port" android:dialogMessage="TCP port for querying musikServer" android:summary="TCP port for querying musikServer" android:dialogTitle="Query port" android:defaultValue="10543"></EditTextPreference>
|
||||
<EditTextPreference android:key="httpport" android:enabled="true" android:inputType="number" android:title="HTTP port" android:dialogMessage="TCP port for streaming music" android:summary="TCP port for streaming music" android:dialogTitle="HTTP port" android:defaultValue="10544"></EditTextPreference>
|
||||
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="Authentication">
|
||||
<EditTextPreference android:key="@string/username" android:enabled="true" android:title="Username" android:summary="Username to identify yourself to the musikServer" android:dialogTitle="Username" android:defaultValue="doep"></EditTextPreference>
|
||||
<EditTextPreference android:dialogTitle="Password" android:key="@string/password" android:inputType="textPassword" android:enabled="true" android:title="Password" android:summary="Password on the musikServer" android:defaultValue="doep"></EditTextPreference>
|
||||
<EditTextPreference android:key="username" android:enabled="true" android:title="Username" android:summary="Username to identify yourself to the musikServer" android:dialogTitle="Username" android:defaultValue="doep"></EditTextPreference>
|
||||
<EditTextPreference android:dialogTitle="Password" android:key="password" android:inputType="textPassword" android:enabled="true" android:title="Password" android:summary="Password on the musikServer" android:defaultValue="doep"></EditTextPreference>
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
|
@ -1,17 +1,11 @@
|
||||
package org.musikcube;
|
||||
|
||||
import android.app.Application;
|
||||
import android.util.Log;
|
||||
|
||||
public class App extends Application {
|
||||
|
||||
@Override
|
||||
public void onCreate(){
|
||||
super.onCreate();
|
||||
Log.i("MUSIKCUBE::APP","Start");
|
||||
org.musikcube.core.Library library = org.musikcube.core.Library.GetInstance();
|
||||
|
||||
library.Startup(this);
|
||||
|
||||
super.onCreate();
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ package org.musikcube;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.musikcube.core.IQuery;
|
||||
import org.musikcube.core.ListQuery;
|
||||
import org.musikcube.core.IQuery.OnQueryResultListener;
|
||||
|
||||
@ -13,7 +14,6 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
@ -107,7 +107,7 @@ public class CategoryList extends ListActivity implements OnQueryResultListener
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState){
|
||||
super.onCreate(savedInstanceState);
|
||||
Log.v("musikcube.CategoryList", "start");
|
||||
//Log.v("musikcube.CategoryList", "start");
|
||||
this.setContentView(R.layout.category_list);
|
||||
|
||||
Intent intent = this.getIntent();
|
||||
@ -136,7 +136,7 @@ public class CategoryList extends ListActivity implements OnQueryResultListener
|
||||
|
||||
|
||||
if(this.category!=null){
|
||||
Log.v("musikcube.CategoryList", "category="+this.category);
|
||||
//Log.v("musikcube.CategoryList", "category="+this.category);
|
||||
// Query for data
|
||||
this.query.category = this.category;
|
||||
|
||||
@ -154,20 +154,20 @@ public class CategoryList extends ListActivity implements OnQueryResultListener
|
||||
library.AddQuery(this.query);
|
||||
|
||||
}else{
|
||||
Log.v("musikcube.CategoryList", "category=null");
|
||||
//Log.v("musikcube.CategoryList", "category=null");
|
||||
|
||||
}
|
||||
|
||||
Log.v("musikcube.CategoryList", "onCreate end");
|
||||
//Log.v("musikcube.CategoryList", "onCreate end");
|
||||
|
||||
}
|
||||
|
||||
public void OnResults(){
|
||||
Log.i("CategoryList::OnResults","In right thread "+this.query.resultsStrings.size());
|
||||
//Log.i("CategoryList::OnResults","In right thread "+this.query.resultsStrings.size());
|
||||
this.listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void OnQueryResults() {
|
||||
public void OnQueryResults(IQuery query) {
|
||||
// Call in right thread
|
||||
this.callbackHandler.post(this.callbackRunnable);
|
||||
}
|
||||
@ -175,7 +175,7 @@ public class CategoryList extends ListActivity implements OnQueryResultListener
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void onListItemClick(ListView l, View v, int position, long id){
|
||||
Log.i("CategoryList::onListItemClick","clicked on "+position+" "+id);
|
||||
//Log.i("CategoryList::onListItemClick","clicked on "+position+" "+id);
|
||||
|
||||
// List category
|
||||
if(this.selectedCategory==null){
|
||||
@ -216,6 +216,7 @@ public class CategoryList extends ListActivity implements OnQueryResultListener
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
org.musikcube.core.Library.GetInstance().AddPointer();
|
||||
startService(new Intent(this, org.musikcube.Service.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.musikcube;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
|
||||
@ -30,6 +31,7 @@ public class Preferences extends PreferenceActivity {
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
org.musikcube.core.Library.GetInstance().AddPointer();
|
||||
startService(new Intent(this, org.musikcube.Service.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import org.musikcube.core.Player;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* @author doy
|
||||
@ -39,9 +38,11 @@ public class Service extends android.app.Service {
|
||||
|
||||
@Override
|
||||
public void onCreate(){
|
||||
Log.i("musikcube::Service","CREATE");
|
||||
//Log.i("musikcube::Service","CREATE");
|
||||
this.player = Player.GetInstance();
|
||||
this.player.service = this;
|
||||
this.library = org.musikcube.core.Library.GetInstance();
|
||||
this.library.Startup(this);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@ -53,6 +54,10 @@ public class Service extends android.app.Service {
|
||||
super.onStart(intent, startId);
|
||||
|
||||
String action = intent.getStringExtra("org.musikcube.Service.action");
|
||||
if(action==null){
|
||||
return;
|
||||
}
|
||||
|
||||
if(action.equals("playlist")){
|
||||
Player player = Player.GetInstance();
|
||||
player.Play(intent.getIntegerArrayListExtra("org.musikcube.Service.tracklist"), intent.getIntExtra("org.musikcube.Service.position", 0));
|
||||
@ -69,7 +74,8 @@ public class Service extends android.app.Service {
|
||||
Player player = Player.GetInstance();
|
||||
player.Play();
|
||||
}
|
||||
if(action.equals("player ended")){
|
||||
if(action.equals("shutdown")){
|
||||
//Log.i("musikcube::Service","Shutdown");
|
||||
this.stopSelf();
|
||||
}
|
||||
|
||||
@ -106,6 +112,8 @@ public class Service extends android.app.Service {
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
//Log.i("musikcube::Service","EXIT");
|
||||
this.library.Exit();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,11 @@ package org.musikcube;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.musikcube.core.IQuery;
|
||||
import org.musikcube.core.Library;
|
||||
import org.musikcube.core.ListQuery;
|
||||
import org.musikcube.core.MetadataQuery;
|
||||
import org.musikcube.core.Track;
|
||||
import org.musikcube.core.IQuery.OnQueryResultListener;
|
||||
|
||||
import android.app.ListActivity;
|
||||
@ -28,6 +32,11 @@ import android.widget.TextView;
|
||||
public class TrackList extends ListActivity implements OnQueryResultListener {
|
||||
|
||||
private ListQuery query = new ListQuery();
|
||||
public java.util.ArrayList<Integer> trackList = new java.util.ArrayList<Integer>();
|
||||
public java.util.TreeMap<Integer, Track> trackCache = new java.util.TreeMap<Integer,Track>();
|
||||
public java.util.TreeSet<Integer> waitingTracks = new java.util.TreeSet<Integer>();
|
||||
|
||||
private java.lang.Object lock = new java.lang.Object();
|
||||
|
||||
// Need handler for callbacks to the UI thread
|
||||
final Handler callbackHandler = new Handler();
|
||||
@ -41,7 +50,7 @@ public class TrackList extends ListActivity implements OnQueryResultListener {
|
||||
|
||||
public class ResultAdapter extends BaseAdapter{
|
||||
|
||||
protected ListQuery query;
|
||||
protected TrackList trackList;
|
||||
protected Context context;
|
||||
|
||||
public ResultAdapter(Context context){
|
||||
@ -49,24 +58,24 @@ public class TrackList extends ListActivity implements OnQueryResultListener {
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return this.query.trackList.size();
|
||||
return this.trackList.trackList.size();
|
||||
}
|
||||
|
||||
public Object getItem(int position) {
|
||||
return this.query.trackList.get(position);
|
||||
return this.trackList.trackList.get(position);
|
||||
}
|
||||
|
||||
public long getItemId(int position) {
|
||||
return this.query.trackList.get(position);
|
||||
return this.trackList.trackList.get(position);
|
||||
}
|
||||
|
||||
public View getView(int position, View view, ViewGroup parent) {
|
||||
TrackItemView item;
|
||||
if(view==null){
|
||||
item = new TrackItemView(this.context,this.query.trackList.get(position));
|
||||
item = new TrackItemView(this.context,this.trackList.GetTrack(position));
|
||||
}else{
|
||||
item = (TrackItemView)view;
|
||||
item.SetTitle(this.query.trackList.get(position));
|
||||
item.SetTitles(this.trackList.GetTrack(position));
|
||||
|
||||
}
|
||||
return item;
|
||||
@ -75,13 +84,13 @@ public class TrackList extends ListActivity implements OnQueryResultListener {
|
||||
}
|
||||
|
||||
private class TrackItemView extends LinearLayout {
|
||||
public TrackItemView(Context context, Integer title) {
|
||||
public TrackItemView(Context context, Track track) {
|
||||
super(context);
|
||||
this.setOrientation(VERTICAL);
|
||||
|
||||
mTitle = new TextView(context);
|
||||
mTitle.setTextSize(22);
|
||||
mTitle.setText(title.toString());
|
||||
this.SetTitles(track);
|
||||
addView(mTitle, new LinearLayout.LayoutParams(
|
||||
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
|
||||
|
||||
@ -90,8 +99,25 @@ public class TrackList extends ListActivity implements OnQueryResultListener {
|
||||
/**
|
||||
* Convenience method to set the title of a CategoryItemView
|
||||
*/
|
||||
public void SetTitle(Integer title) {
|
||||
mTitle.setText(title.toString());
|
||||
public void SetTitles(Track track) {
|
||||
if(track!=null){
|
||||
String text = "";
|
||||
String trackNumber = track.metadata.get("track");
|
||||
String title = track.metadata.get("title");
|
||||
if(trackNumber!=null){
|
||||
text += trackNumber+". ";
|
||||
}
|
||||
if(title!=null){
|
||||
text += title;
|
||||
}
|
||||
if(!text.equals("")){
|
||||
mTitle.setText(text);
|
||||
}else{
|
||||
mTitle.setText("unknown");
|
||||
}
|
||||
}else{
|
||||
mTitle.setText("loading");
|
||||
}
|
||||
}
|
||||
|
||||
private TextView mTitle;
|
||||
@ -110,7 +136,7 @@ public class TrackList extends ListActivity implements OnQueryResultListener {
|
||||
this.query.SetResultListener(this);
|
||||
|
||||
this.listAdapter = new ResultAdapter(this);
|
||||
this.listAdapter.query = this.query;
|
||||
this.listAdapter.trackList = this;
|
||||
setListAdapter(this.listAdapter);
|
||||
|
||||
this.setTitle("musikCube: Tracks");
|
||||
@ -134,28 +160,39 @@ public class TrackList extends ListActivity implements OnQueryResultListener {
|
||||
}
|
||||
|
||||
public void OnResults(){
|
||||
Log.i("TrackList::OnResults","In right thread "+this.query.trackList.size());
|
||||
this.listAdapter.notifyDataSetChanged();
|
||||
//Log.i("TrackList::OnResults","In right thread "+this.query.trackList.size());
|
||||
|
||||
if(this.query!=null){
|
||||
this.trackList = this.query.trackList;
|
||||
this.query = null;
|
||||
this.listAdapter.notifyDataSetChanged();
|
||||
}else{
|
||||
//this is metadataquery results
|
||||
// notify that list should update
|
||||
this.listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnQueryResults() {
|
||||
public void OnQueryResults(IQuery query) {
|
||||
|
||||
if(query.type=="TrackMetadata"){
|
||||
MetadataQuery mdQuery = (MetadataQuery)query;
|
||||
synchronized(this.lock){
|
||||
int trackCount = mdQuery.resultTracks.size();
|
||||
for(int i=0;i<trackCount;i++){
|
||||
Track track = mdQuery.resultTracks.get(i);
|
||||
this.waitingTracks.remove(track.id);
|
||||
this.trackCache.put(track.id,track);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Call in right thread
|
||||
this.callbackHandler.post(this.callbackRunnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onListItemClick(ListView l, View v, int position, long id){
|
||||
/* Log.i("CategoryList::onListItemClick","clicked on "+position+" "+id);
|
||||
if(this.nextCategoryList.equals("")){
|
||||
// List tracks
|
||||
}else{
|
||||
Intent intent = new Intent(this, CategoryList.class);
|
||||
intent.putExtra("org.musikcube.CategoryList.listCategory", this.nextCategoryList);
|
||||
intent.putExtra("org.musikcube.CategoryList.selectedCategory", this.category);
|
||||
intent.putExtra("org.musikcube.CategoryList.selectedCategoryId", (int)id);
|
||||
startActivity(intent);
|
||||
}*/
|
||||
|
||||
protected void onListItemClick(ListView l, View v, int position, long id){
|
||||
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);
|
||||
@ -179,5 +216,51 @@ public class TrackList extends ListActivity implements OnQueryResultListener {
|
||||
super.onResume();
|
||||
org.musikcube.core.Library.GetInstance().AddPointer();
|
||||
}
|
||||
|
||||
public Track GetTrack(int position){
|
||||
synchronized(this.lock){
|
||||
Integer trackId = this.trackList.get(position);
|
||||
Track track = this.trackCache.get(trackId);
|
||||
if(track==null){
|
||||
//check if it's in the "requested" cache
|
||||
if(!this.waitingTracks.contains(trackId)){
|
||||
// request the track
|
||||
MetadataQuery query = new MetadataQuery();
|
||||
query.requestedMetakeys.add("track");
|
||||
query.requestedMetakeys.add("title");
|
||||
query.requestedMetakeys.add("visual_artist");
|
||||
query.SetResultListener(this);
|
||||
|
||||
query.requestedTracks.add(trackId);
|
||||
this.waitingTracks.add(trackId);
|
||||
|
||||
// Add some more tracks
|
||||
int trackListSize = this.trackList.size();
|
||||
for(int i=position;i<position+10 && i<trackListSize;i++){
|
||||
Integer nextTrackId = this.trackList.get(i);
|
||||
if(!this.IsTrackInCache(nextTrackId)){
|
||||
query.requestedTracks.add(nextTrackId);
|
||||
this.waitingTracks.add(nextTrackId);
|
||||
}
|
||||
}
|
||||
|
||||
Library.GetInstance().AddQuery(query);
|
||||
}
|
||||
}
|
||||
return track;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean IsTrackInCache(int trackId){
|
||||
Track track = this.trackCache.get(trackId);
|
||||
if(track==null){
|
||||
//check if it's in the "requested" cache
|
||||
if(!this.waitingTracks.contains(trackId)){
|
||||
// request the track
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ public class IQuery extends Object{
|
||||
public static int uidCounter = 0;
|
||||
|
||||
public interface OnQueryResultListener{
|
||||
public void OnQueryResults();
|
||||
public void OnQueryResults(IQuery query);
|
||||
}
|
||||
|
||||
protected OnQueryResultListener listener = null;
|
||||
|
@ -7,6 +7,9 @@ import java.net.*;
|
||||
import java.io.*;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.*;
|
||||
import doep.xml.*;
|
||||
|
||||
@ -33,6 +36,13 @@ public class Library implements Runnable{
|
||||
private Socket socket;
|
||||
|
||||
private Context context;
|
||||
private Integer status = 0;
|
||||
|
||||
|
||||
public static final int STATUS_SHUTDOWN = 0;
|
||||
public static final int STATUS_CONNECTING = 1;
|
||||
public static final int STATUS_AUTHENTICATING= 2;
|
||||
public static final int STATUS_CONNECTED = 3;
|
||||
|
||||
int connections = 0;
|
||||
|
||||
@ -51,6 +61,36 @@ public class Library implements Runnable{
|
||||
}
|
||||
return Library.library;
|
||||
}
|
||||
|
||||
private OnLibraryStatusListener statusListener = null;
|
||||
|
||||
public interface OnLibraryStatusListener{
|
||||
public void OnLibraryStatusChange(int status);
|
||||
}
|
||||
|
||||
public void SetStatusListener(OnLibraryStatusListener statusListener){
|
||||
synchronized(this.status){
|
||||
this.statusListener = statusListener;
|
||||
if(this.statusListener!=null){
|
||||
this.statusListener.OnLibraryStatusChange(this.status.intValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetStatus(int status){
|
||||
synchronized(this.status){
|
||||
this.status = status;
|
||||
if(this.statusListener!=null){
|
||||
this.statusListener.OnLibraryStatusChange(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int GetStatus(){
|
||||
synchronized(this.status){
|
||||
return this.status.intValue();
|
||||
}
|
||||
}
|
||||
|
||||
public void AddPointer(){
|
||||
synchronized(this.notifier){
|
||||
@ -80,7 +120,7 @@ public class Library implements Runnable{
|
||||
|
||||
|
||||
public void Startup(Context context){
|
||||
if(context!=null){
|
||||
// if(context!=null){
|
||||
this.context = context;
|
||||
|
||||
// Startup thread when the application sends the context for the first time
|
||||
@ -88,7 +128,7 @@ public class Library implements Runnable{
|
||||
this.running = true;
|
||||
this.thread.start();
|
||||
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
public void Restart(){
|
||||
@ -160,13 +200,19 @@ public class Library implements Runnable{
|
||||
// First try to connect
|
||||
try{
|
||||
synchronized (notifier) {
|
||||
this.host = this.context.getString(R.string.host);
|
||||
int queryPort = Integer.parseInt(this.context.getString(R.string.queryport));
|
||||
this.httpPort = Integer.parseInt(this.context.getString(R.string.httpport));
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.context);
|
||||
this.host = prefs.getString("host","");
|
||||
int queryPort = Integer.parseInt(prefs.getString("queryport","10543"));
|
||||
this.httpPort = Integer.parseInt(prefs.getString("httpport","10544"));
|
||||
|
||||
this.SetStatus(STATUS_CONNECTING);
|
||||
|
||||
this.socket = new java.net.Socket(host,queryPort);
|
||||
}
|
||||
//Log.v("Library::socket","Successfully connected to "+this.host+":"+this.queryPort);
|
||||
|
||||
this.SetStatus(STATUS_AUTHENTICATING);
|
||||
|
||||
doep.xml.Reader reader = new doep.xml.Reader(this.socket.getInputStream());
|
||||
//Log.v("Library::run","Reader started");
|
||||
{
|
||||
@ -250,6 +296,8 @@ public class Library implements Runnable{
|
||||
|
||||
}
|
||||
|
||||
this.SetStatus(STATUS_SHUTDOWN);
|
||||
|
||||
synchronized (notifier) {
|
||||
if(this.connections!=0){
|
||||
try{
|
||||
@ -259,7 +307,7 @@ public class Library implements Runnable{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
while(this.connections==0){
|
||||
try{
|
||||
this.notifier.wait();
|
||||
@ -267,7 +315,7 @@ public class Library implements Runnable{
|
||||
catch(Exception x){
|
||||
|
||||
}
|
||||
}
|
||||
}*/
|
||||
/* int countDown = 10;
|
||||
while(!this.exit && !this.restart){
|
||||
try{
|
||||
@ -278,7 +326,12 @@ public class Library implements Runnable{
|
||||
}
|
||||
}*/
|
||||
|
||||
Log.i("musikcube::LIB","exit? "+this.exit);
|
||||
|
||||
if(this.exit){
|
||||
Intent intent = new Intent(this.context, org.musikcube.Service.class);
|
||||
intent.putExtra("org.musikcube.Service.action", "shutdown");
|
||||
this.context.startService(intent);
|
||||
return;
|
||||
}
|
||||
this.restart = false;
|
||||
@ -293,8 +346,11 @@ public class Library implements Runnable{
|
||||
try{
|
||||
doep.xml.Writer writer = new doep.xml.Writer(this.socket.getOutputStream());
|
||||
{
|
||||
String username = this.context.getString(R.string.username);
|
||||
String password = this.context.getString(R.string.password);
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.context);
|
||||
this.host = prefs.getString("host","");
|
||||
|
||||
String username = prefs.getString("username","");
|
||||
String password = prefs.getString("password","");
|
||||
|
||||
// Authenticate
|
||||
WriterNode authNode = writer.ChildNode("authentication");
|
||||
@ -303,6 +359,8 @@ public class Library implements Runnable{
|
||||
authNode.End();
|
||||
}
|
||||
|
||||
this.SetStatus(STATUS_CONNECTED);
|
||||
|
||||
// Wait for queries to send
|
||||
while(this.running){
|
||||
IQuery query = null;
|
||||
@ -314,6 +372,7 @@ public class Library implements Runnable{
|
||||
synchronized(this.notifier){
|
||||
this.shutdownCounter--;
|
||||
if(this.shutdownCounter==0){
|
||||
this.exit = true;
|
||||
this.Restart();
|
||||
}
|
||||
}
|
||||
@ -349,6 +408,8 @@ public class Library implements Runnable{
|
||||
Log.e("Library::WriteThread","E "+x.getMessage());
|
||||
}
|
||||
|
||||
this.SetStatus(STATUS_SHUTDOWN);
|
||||
|
||||
// Notify the "read"-thread by closing the socket
|
||||
try {
|
||||
this.socket.close();
|
||||
|
@ -81,7 +81,7 @@ public class ListQuery extends IQuery {
|
||||
|
||||
// TODO: Notify that results are here
|
||||
if(this.listener!=null){
|
||||
this.listener.OnQueryResults();
|
||||
this.listener.OnQueryResults(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,7 @@ public class MetadataQuery extends IQuery {
|
||||
}
|
||||
tracksNode.content = tracks;
|
||||
|
||||
|
||||
queryNode.End();
|
||||
}
|
||||
|
||||
@ -62,10 +63,13 @@ public class MetadataQuery extends IQuery {
|
||||
mdNode.End();
|
||||
track.metadata.put(mdNode.attributes.get("k"), mdNode.content);
|
||||
}
|
||||
|
||||
this.resultTracks.add(track);
|
||||
|
||||
}
|
||||
|
||||
if(this.listener!=null){
|
||||
this.listener.OnQueryResults();
|
||||
this.listener.OnQueryResults(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,11 +106,11 @@ public class Player implements TrackPlayer.OnTrackStatusListener{
|
||||
if(this.library!=null){
|
||||
this.library.RemovePointer();
|
||||
this.library = null;
|
||||
|
||||
/*
|
||||
Intent intent = new Intent(this.service, org.musikcube.Service.class);
|
||||
intent.putExtra("org.musikcube.Service.action", "player ended");
|
||||
this.service.startService(intent);
|
||||
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,18 +3,21 @@ package org.musikcube;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.os.Handler;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.musikcube.CategoryList;
|
||||
import org.musikcube.core.Library;
|
||||
import org.musikcube.core.Library.OnLibraryStatusListener;
|
||||
|
||||
|
||||
public class main extends Activity {
|
||||
public class main extends Activity implements OnLibraryStatusListener {
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
@ -22,12 +25,16 @@ public class main extends Activity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
|
||||
ImageButton genreButton = (ImageButton)findViewById(R.id.GenresButton);
|
||||
Button genreButton = (Button)findViewById(R.id.GenresButton);
|
||||
genreButton.setOnClickListener(this.onGenreClick);
|
||||
|
||||
ImageButton artistsButton = (ImageButton)findViewById(R.id.ArtistsButton);
|
||||
artistsButton.setOnClickListener(this.onArtistsClick);
|
||||
genreButton.setEnabled(false);
|
||||
|
||||
Button artistsButton = (Button)findViewById(R.id.ArtistsButton);
|
||||
artistsButton.setOnClickListener(this.onArtistsClick);
|
||||
|
||||
artistsButton.setEnabled(false);
|
||||
|
||||
}
|
||||
|
||||
private OnClickListener onGenreClick = new OnClickListener() {
|
||||
@ -59,7 +66,7 @@ public class main extends Activity {
|
||||
}
|
||||
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
Log.i("MC2.onContextItemSelected","item "+item.getItemId()+" "+R.id.context_settings);
|
||||
//Log.i("MC2.onContextItemSelected","item "+item.getItemId()+" "+R.id.context_settings);
|
||||
switch (item.getItemId()) {
|
||||
case R.id.context_settings:
|
||||
Intent intent = new Intent(main.this, Preferences.class);
|
||||
@ -74,12 +81,62 @@ public class main extends Activity {
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
org.musikcube.core.Library.GetInstance().RemovePointer();
|
||||
org.musikcube.core.Library.GetInstance().SetStatusListener(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
org.musikcube.core.Library.GetInstance().AddPointer();
|
||||
org.musikcube.core.Library.GetInstance().SetStatusListener(this);
|
||||
startService(new Intent(this, org.musikcube.Service.class));
|
||||
}
|
||||
|
||||
public void OnLibraryStatusChange(int status) {
|
||||
this.libStatusHandler.post(this.libStatusRunnable);
|
||||
}
|
||||
|
||||
final Handler libStatusHandler = new Handler();
|
||||
|
||||
// Create runnable for posting
|
||||
final Runnable libStatusRunnable = new Runnable() {
|
||||
public void run() {
|
||||
OnLibraryStatus();
|
||||
}
|
||||
};
|
||||
|
||||
public void OnLibraryStatus() {
|
||||
int status = Library.GetInstance().GetStatus();
|
||||
Button genreButton = (Button)findViewById(R.id.GenresButton);
|
||||
Button artistsButton = (Button)findViewById(R.id.ArtistsButton);
|
||||
|
||||
if(status==Library.STATUS_CONNECTED){
|
||||
genreButton.setEnabled(true);
|
||||
artistsButton.setEnabled(true);
|
||||
}else{
|
||||
genreButton.setEnabled(false);
|
||||
artistsButton.setEnabled(false);
|
||||
}
|
||||
|
||||
TextView statusText = (TextView)findViewById(R.id.StatusView);
|
||||
|
||||
switch(status){
|
||||
case Library.STATUS_AUTHENTICATING:
|
||||
statusText.setText("Status: Authenticating");
|
||||
break;
|
||||
case Library.STATUS_CONNECTING:
|
||||
statusText.setText("Status: Connecting");
|
||||
break;
|
||||
case Library.STATUS_SHUTDOWN:
|
||||
statusText.setText("Status: Disconnected");
|
||||
break;
|
||||
case Library.STATUS_CONNECTED:
|
||||
statusText.setText("Status: Connected");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user