From 29ac94bc27a1031d023f2ce54e8fe8083c170b53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96nnerby?= Date: Fri, 21 Aug 2009 06:38:15 +0000 Subject: [PATCH] Fixed some bug in TrackPlayer. Modified some graphics. --- src/android/AndroidManifest.xml | 2 +- src/android/res/drawable/ic_media_next.png | Bin 1309 -> 1323 bytes src/android/res/drawable/ic_media_pause.png | Bin 512 -> 519 bytes src/android/res/drawable/ic_media_play.png | Bin 919 -> 931 bytes .../res/drawable/ic_media_previous.png | Bin 1295 -> 1305 bytes .../src/org/musikcube/PlayerControl.java | 9 +++ src/android/src/org/musikcube/Service.java | 4 ++ .../src/org/musikcube/core/Library.java | 54 ++++++++---------- .../src/org/musikcube/core/Player.java | 21 ++++++- .../src/org/musikcube/core/TrackPlayer.java | 41 ++++++------- 10 files changed, 73 insertions(+), 58 deletions(-) diff --git a/src/android/AndroidManifest.xml b/src/android/AndroidManifest.xml index ac4467e04..75d40e1f0 100644 --- a/src/android/AndroidManifest.xml +++ b/src/android/AndroidManifest.xml @@ -3,7 +3,7 @@ package="org.musikcube" android:versionCode="1" android:versionName="1.0"> - + diff --git a/src/android/res/drawable/ic_media_next.png b/src/android/res/drawable/ic_media_next.png index 84f38e8f8739ece4b3c85368bafe99e910af917b..14a8924225c5f356b7835118158f948895891fe3 100644 GIT binary patch delta 1266 zcmVr6`-7 zh-m|rKE}iOyRUt3?b|vx_^>a#FE8izy!$)n+;e{KyxWqgsedVEF^7g(A*eGx~Fw?J|N#g-&zQY8vy3^;{;IR-R}J+6b{*KHrt4EgR={|%P{)K9M0DT zdxKvl5(y*L4_K_0Q&9H;^Y5bsP|C2(C$XW}=Ge8^%kk0pnyMG8D(V{Qgr1*zZq5d% zeY3Wn=XuZA#DCbj=r2)+kQA0%ZC0wk56s^SE&+=O7{V}A#&5*!zILC5Yv7h+r{#El z0Xs|2MBx@CNkRjmE%C9qwYjOe8f z--Hr=9_kC#uYP{DStIYBUIH#DBj85#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FXFG)8IF0W-Wa*hx67x9Dcjv>*>bhoA$_<-XCU=1U_2%kj zRl?-~^u9B_1KqCQ);lcc6q> z>J?WgM=8P-hJS2^sd7)wLpjnm)cJL{R}4ow513GPdizjlLpgLG7z<}8hjyUN<%ooG zcn314n3`&zXLAyVcA&T|u7BH`(?hW+NF2ThdH;Z+w_7jbp&Vrw7(*T7rr|_z_&&g| z4W&HwZm&>|)Cu*95}pj6AVWFIHawi<>1d2HYh3(@13KIu9W<1~orpUjYUH`g~^k^0A=D00000NkvXXu0mjfRF}~s diff --git a/src/android/res/drawable/ic_media_play.png b/src/android/res/drawable/ic_media_play.png index 7aa7af8ad508313c84bd1815d274c112ed239d78..287ac6fbfbb2a966a669d0b1a6011e6bd66c2afc 100644 GIT binary patch delta 871 zcmV-t1DO1m2crj&NqY?$ZCN?l-gs2)jsn*b2>a4KHAaV;Q|r|;n6av@w;9ERtgYU#wtBZ zrixTC!OYCfTz?ZLg}a1I3<42uX9%F80-8n?To^9s$@J&+c>oV&GMO8o%0(DA*h)YF zE1eg>i~S~c2@^u!!ra0gAlnlijW*k=fTn^1XjDW6FZczR38j*$OOeq?Nct)DM#rLU z_Bf#t5K(1ss|ul_QXA_VO^FAIeowpSNc>^k0i=`sO@Dr^b`v0~YAHdD{ozUzu!~N;^>Fe?Fc!w}9IBNC*T@5W9OMF3_8%7K?vIuHHD$c>k+OT4FoQlK^t$8AyXey7h)r^F8J2jy24O*IAore zlF_23)PG5>^X)cKK<}fsKBlE)0|;b66MzmRn;baLwQx&;-oP8>G_9I|DH~P@M}4OT za@yBuiq7_2?V0AzaWn9I$=B)Iv^ouur3vKi!^dbQLBGClS&HYXQ~_~UEyy>PqT&tQ3lAK-uO zSYS=4$9thP14sMh?*d12FpB`Zw4+5S>^KKNIVa_mK=wwD+p`R1`BT-=2Kdab{Fp>X xqDsN393qWMDh1%WY+col$=<)=Znl2{3;@$mU+q-e!L_t(|+U!?PXwy&}PPZIhrDz5d49r7yFnid+>P|z%g2)Q< zu!Ca_PG_pDYpJkx!^5C=DLVxZ%1*-6NhVgh9flc>*&QOSCx+V_3$`~7*pIEuw0(aP3Fw79jL0QsjEv46=}4|IKSJK%nom`iNg zLBO$}4*>X4nx^B-2y<0aDU;2J!kX|L#v%~;au_CXQWWK+I;n2diB9=0`-a&GHjZ3q z9LV(_iU|}|(R-vKy?1xHdt=eq$>r5$8b}<2M;oBVPurXjkpQd$5wb)?8xx42h6aaj zFahQsP@e`OUVnQCs1*ftU`-LY5M0nZJZC%?0GxHZ-D9B26&SZQm4F6TJuib-dKaRZ z>&&=+(0>=m1|rc&Pg4~zRL}r%MRf48Ux1lNZ=ZKyDmoRXkJGm!6Ol{JaY7tWRjkAe zh17~t9i1KBY={k|SJPd=J3$wa7P*JqZsR6UmAa(_HGhuy27JTeiEtc5iw186`x_=8 ztFmc^>fPfes(GjC;d*X%W;WzG>$w>m4f>f;#?`P7m}(f|Smg`G95+eXK`C~GWdmb@ z87JYKhOj-|P#9XgUPb#y1A!`LFvcY^4sWmbVt6uq4c0n;pfEHYPPNXf$rw>n?W7iS z{c9A+dw+6iF(V~oAo{;B027F`IB+o|X4dB)&A-u3)4B;*vf)1AXzmmvXY5o~u z1wONxS%T;5sbs297Xf`S^6%k;n+YFF+tPdP0k@Jb#urwG1a^ zQg|gig;hlW|JraSq)*TU>Oi$-A+a87JG(pE{C^Uk%zw|P_#`hJI29u;nIdEbCTmGR z!cwIzNr0U{)~Y3t{$o?l0z9_yU&y3fG7UV-6>{H%Re_g2NiSh8B2j zEBl4?S=t22U&Am7Rgu{AlFW>KgsjO$A%3OSQZKUE>>|A0$Vo9uwxm3$L002ovPDHLkV1ku^kQ4v_ diff --git a/src/android/res/drawable/ic_media_previous.png b/src/android/res/drawable/ic_media_previous.png index 1bba54415aeeb985fce34d0b03e15a8a8aa175c7..9a79d08136f35c7ae830a79f7c72ae537e2b8f69 100644 GIT binary patch delta 1248 zcmV<61Rwj43YiL!Nq@UZL_t(|+U!?vOdDkwf3FC^ys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ENd zq;ID4;Ba22*NHPTGn2Vrb3^bgUr)v6w{u^fn;cJ#-vpo!NDcXS>PG6i=5hawf`@}o zl@6u9L#9_(XoHS)JAj8DHS51->j2goz<&Y^02v=+#N$`s2mk;807*qoM6N<$f|Qs^ A`v3p{ diff --git a/src/android/src/org/musikcube/PlayerControl.java b/src/android/src/org/musikcube/PlayerControl.java index 46cfecaaa..083e1dc14 100644 --- a/src/android/src/org/musikcube/PlayerControl.java +++ b/src/android/src/org/musikcube/PlayerControl.java @@ -46,6 +46,8 @@ public class PlayerControl extends Activity implements OnTrackUpdateListener { nextButton.setOnClickListener(this.onNextClick); ImageButton pauseButton = (ImageButton)findViewById(R.id.MediaPause); pauseButton.setOnClickListener(this.onPauseClick); + ImageButton prevButton = (ImageButton)findViewById(R.id.MediaPrev); + prevButton.setOnClickListener(this.onPrevClick); this.callbackTrackPositionsUpdateHandler.postDelayed(callbackTrackPositionsUpdateRunnable,500); } @@ -57,6 +59,13 @@ public class PlayerControl extends Activity implements OnTrackUpdateListener { startService(intent); } }; + private OnClickListener onPrevClick = new OnClickListener() { + public void onClick(View v){ + Intent intent = new Intent(PlayerControl.this, org.musikcube.Service.class); + intent.putExtra("org.musikcube.Service.action", "prev"); + startService(intent); + } + }; private OnClickListener onPauseClick = new OnClickListener() { public void onClick(View v){ Intent intent = new Intent(PlayerControl.this, org.musikcube.Service.class); diff --git a/src/android/src/org/musikcube/Service.java b/src/android/src/org/musikcube/Service.java index 8e96adf71..ec620fb0b 100644 --- a/src/android/src/org/musikcube/Service.java +++ b/src/android/src/org/musikcube/Service.java @@ -82,6 +82,10 @@ public class Service extends android.app.Service { Player player = Player.GetInstance(); player.Next(); } + if(action.equals("prev")){ + Player player = Player.GetInstance(); + player.Prev(); + } if(action.equals("stop")){ Player player = Player.GetInstance(); player.Stop(); diff --git a/src/android/src/org/musikcube/core/Library.java b/src/android/src/org/musikcube/core/Library.java index 12e23c62f..2722b7752 100644 --- a/src/android/src/org/musikcube/core/Library.java +++ b/src/android/src/org/musikcube/core/Library.java @@ -103,6 +103,7 @@ public class Library implements Runnable{ }else{ this.shutdownCounter = -1; } + this.notifier.notifyAll(); } } public void RemovePointer(){ @@ -113,27 +114,24 @@ public class Library implements Runnable{ }else{ this.shutdownCounter = -1; } + this.notifier.notifyAll(); } } public void Startup(Context context){ -// if(context!=null){ - this.context = context; - - // Startup thread when the application sends the context for the first time - this.thread = new Thread(this); - this.running = true; - this.thread.start(); - -// } + this.context = context; + + // Startup thread when the application sends the context for the first time + this.thread = new Thread(this); + this.running = true; + this.thread.start(); } public void Restart(){ synchronized(this.notifier){ this.running = false; this.restart = true; -// this.Startup(null); if(this.socket!=null){ try { this.socket.shutdownInput(); @@ -175,7 +173,6 @@ public class Library implements Runnable{ private WriterThreadHelper writerThreadHelper; protected Library(){ -// this.writerThreadHelper = new WriterThreadHelper(this); } public void WaitForAuthroization(){ @@ -305,26 +302,6 @@ public class Library implements Runnable{ } } -/* - while(this.connections==0){ - try{ - this.notifier.wait(); - } - catch(Exception x){ - - } - }*/ -/* int countDown = 10; - while(!this.exit && !this.restart){ - try{ - this.notifier.wait(2000); - } - catch(Exception x){ - - } - }*/ - - //Log.i("musikcube::LIB","exit? "+this.exit); if(this.exit){ Intent intent = new Intent(this.context, org.musikcube.Service.class); @@ -393,6 +370,11 @@ public class Library implements Runnable{ } // Send the query query.SendQuery(writer); + }else{ + // Send a ping + WriterNode pingNode = writer.ChildNode("ping"); + pingNode.End(); + } } @@ -450,4 +432,14 @@ public class Library implements Runnable{ } } + public String GetTrackURL(int trackId){ + synchronized (notifier) { + if(this.status==STATUS_CONNECTED){ + String trackURL = "http://"+this.host+":"+this.httpPort+"/track/?track_id="+trackId+"&auth_key="+this.authorization; + return trackURL; + } + } + return null; + } + } diff --git a/src/android/src/org/musikcube/core/Player.java b/src/android/src/org/musikcube/core/Player.java index 887ec034d..7ae481029 100644 --- a/src/android/src/org/musikcube/core/Player.java +++ b/src/android/src/org/musikcube/core/Player.java @@ -70,8 +70,8 @@ public class Player implements TrackPlayer.OnTrackStatusListener, OnQueryResultL synchronized(this.lock){ if(this.nowPlaying.size()>position && position>=0){ int trackId = this.nowPlaying.get(position); - String url = "http://"+this.library.host+":"+this.library.httpPort+"/track/?track_id="+trackId+"&auth_key="+this.library.authorization; - TrackPlayer player = new TrackPlayer(url,trackId); + //String url = "http://"+this.library.host+":"+this.library.httpPort+"/track/?track_id="+trackId+"&auth_key="+this.library.authorization; + TrackPlayer player = new TrackPlayer(trackId); return player; } } @@ -165,6 +165,23 @@ public class Player implements TrackPlayer.OnTrackStatusListener, OnQueryResultL } } + public void Prev(){ + synchronized(this.lock){ + this.currentTrack = new Track(); + this.position--; + if(this.position<0){ + this.position = 0; + } + + if(this.position>=this.nowPlaying.size()){ + this.StopAllTracks(); + this.End(); + }else{ + this.Play(); + } + } + } + public void Stop(){ synchronized(this.lock){ this.StopAllTracks(); diff --git a/src/android/src/org/musikcube/core/TrackPlayer.java b/src/android/src/org/musikcube/core/TrackPlayer.java index f125481ee..c569edf2f 100644 --- a/src/android/src/org/musikcube/core/TrackPlayer.java +++ b/src/android/src/org/musikcube/core/TrackPlayer.java @@ -7,7 +7,6 @@ public class TrackPlayer implements Runnable, MediaPlayer.OnCompletionListener, public int trackId = 0; private Thread thread; - private String url; private java.lang.Object lock = new java.lang.Object(); private MediaPlayer mediaPlayer; private int buffer = 0; @@ -21,7 +20,6 @@ public class TrackPlayer implements Runnable, MediaPlayer.OnCompletionListener, public static final int STATUS_EXIT = 10; public void run() { - Log.v("mC2::TrackPlayer", "Thread started "+this.url); synchronized(this.lock){ this.mediaPlayer = new MediaPlayer(); } @@ -30,11 +28,22 @@ public class TrackPlayer implements Runnable, MediaPlayer.OnCompletionListener, this.mediaPlayer.setOnCompletionListener(this); this.mediaPlayer.setOnErrorListener(this); this.mediaPlayer.setOnBufferingUpdateListener(this); - - this.mediaPlayer.setDataSource(this.url); - Log.v("mC2::TrackPlayer", "Preparing "+this.url); - this.mediaPlayer.prepare(); - Log.v("mC2::TrackPlayer", "Prepared "+this.url); + + { + String url = Library.GetInstance().GetTrackURL(this.trackId); + while(url==null && (this.status==STATUS_PREPARED || this.status==STATUS_PLAYING)){ + Log.v("mC2::TrackPlayer","Retrying "+this.trackId); + this.lock.wait(250); + url = Library.GetInstance().GetTrackURL(this.trackId); + } + + if(url==null){ + this.status = STATUS_EXIT; + }else{ + this.mediaPlayer.setDataSource(url); + this.mediaPlayer.prepare(); + } + } synchronized(this.lock){ if(this.listener!=null){ @@ -49,8 +58,6 @@ public class TrackPlayer implements Runnable, MediaPlayer.OnCompletionListener, synchronized(this.lock){ currentStatus = this.status; } - - Log.v("mC2::TrackPlayer", "Start? "+this.url); if(currentStatus==STATUS_PLAYING) this.mediaPlayer.start(); @@ -64,7 +71,6 @@ public class TrackPlayer implements Runnable, MediaPlayer.OnCompletionListener, // The track is almost done this.almostDoneSend = true; if(this.listener!=null){ - Log.v("mC2::TrackPlayer", "OnTrackAlmostDone "+this.url); this.listener.OnTrackAlmostDone(this); } } @@ -73,7 +79,6 @@ public class TrackPlayer implements Runnable, MediaPlayer.OnCompletionListener, } } - Log.v("mC2::TrackPlayer", "Stopping "+this.url); this.mediaPlayer.stop(); this.mediaPlayer.release(); @@ -86,29 +91,17 @@ public class TrackPlayer implements Runnable, MediaPlayer.OnCompletionListener, synchronized(this.lock){ this.status = STATUS_EXIT; } - Log.v("mC2::TrackPlayer", "ExitCallbacks "+this.url); this.CallListener(); - Log.v("mC2::TrackPlayer", "END "+this.url); } - public TrackPlayer(String url,int trackId){ + public TrackPlayer(int trackId){ this.trackId = trackId; - this.url = url; this.thread = new Thread(this); this.thread.start(); } -/* public TrackPlayer(String url,boolean start){ - this.url = url; - if(start==true){ - this.status = STATUS_PLAYING; - } - this.thread = new Thread(this); - this.thread.start(); - }*/ - private void Exit(){ synchronized(this.lock){ this.status = STATUS_EXIT;