Remote Service, MediaPlayer

  • Antworten:0
John Do
  • Forum-Beiträge: 36

10.05.2012, 17:08:49 via Website

Hallo liebe Mitentwickler,

ich wollte mittels Remote Service Hintergrundmusik abspielen. Bekomme jedoch immer wieder folgenden Fehler.

Application Aidl(in process android.test.musicaidl:MSint) is not responding.

Ich dachte gerade durch die Verwendung eines Remote Service wird ein ARN verhinert.
Als Logfile Meldung erhalte ich folgendes:
05-10 14:31:22.434: I/dalvikvm(94): threadid=7: reacting to signal 3
05-10 14:31:22.454: I/dalvikvm(94): Wrote stack trace to '/data/anr/traces.txt'
05-10 14:31:22.635: I/Process(52): Sending signal. PID: 92 SIG: 3
05-10 14:31:22.635: I/dalvikvm(92): threadid=7: reacting to signal 3
05-10 14:31:22.654: I/dalvikvm(92): Wrote stack trace to '/data/anr/traces.txt'
05-10 14:31:23.013: I/ARMAssembler(52): generated scanline__00000077:03515104_00000000_00000000 [ 33 ipp] (47 ins) at [0x3f3280:0x3f333c] in 405203 ns
05-10 14:31:23.033: I/ARMAssembler(52): generated scanline__00000177:03515104_00001001_00000000 [ 91 ipp] (114 ins) at [0x3f3340:0x3f3508] in 520967 ns

Ich habe gelesen, dass man einige Methoden asynchrone laufen lassen soll. Welche? Der Service läuft in einem eigenen Thread und der MediaPlayer ist als Objekt dem Service zugeordnet. Warum also der Fehler?

Das verwendete Interface hat folgende Struktur.
1package android.test.musicaidl;
2interface MSint {
3 void nextSong();
4 void pauseSong();
5 void startSong();}

Ich nutze zwei Activties und springe immer hin und her.
1public class MusicPlayerAidlActivity extends Activity {
2
3 BGMS bgmusic;
4 private MSint inter;
5 Button buttonStart, buttonStop;
6
7 /** Called when the activity is first created. */
8 @Override
9 public void onCreate(Bundle savedInstanceState) {
10 super.onCreate(savedInstanceState);
11 setContentView(R.layout.main);
12
13 buttonStart = (Button) findViewById(R.id.buttonStart);
14 buttonStart.setOnClickListener(Start);
15
16 }
17
18 OnClickListener Start = new OnClickListener() {
19 public void onClick(View arg0) {
20 startActivity(new Intent(MusicPlayerAidlActivity.this,
21 Activityzwei.class));
22 }
23 };
24
25 private ServiceConnection mConnection = new ServiceConnection() {
26
27 public void onServiceConnected(ComponentName name, IBinder binder) {
28 inter = MSint.Stub.asInterface(binder);
29 Log.i("Info", "inter");
30 }
31
32 public void onServiceDisconnected(ComponentName name) {
33 Log.i("Info", "in onServiceDisconnected");
34 inter = null;
35 }
36 };
37
38 void doBindService() {
39 Log.i("Info", "doBindService");
40 this.bindService(new Intent(this, BGMS.class), mConnection,
41 Context.BIND_AUTO_CREATE);
42 }
43
44 @Override
45 protected void onStart() {
46 super.onStart();
47 if (bgmusic == null) {
48 doBindService();
49 Log.i("Info", "StartA onStart bgmusic == null");
50 } else {
51 try {
52 inter.startSong();
53 } catch (RemoteException e) {
54 // TODO Auto-generated catch block
55 e.printStackTrace();
56 }
57 Log.i("Info", "StartA onStart bgmusic.startSong");
58 }
59 }
60
61 @Override
62 protected void onDestroy() {
63 super.onDestroy();
64 this.unbindService(mConnection);}
65}

Der Service enthält folgenden Code:
1public class BGMS extends Service{
2
3 MediaPlayer player = new MediaPlayer();
4 private int currentsong = 0;
5// private static final String TAG = "MyService";
6 private int [] song = {R.raw.uffiewordy, R.raw.blendergameengine};
7
8 @Override
9 public IBinder onBind(Intent intent) {
10 // TODO Auto-generated method stub
11 return mBinder;
12 }
13
14 @Override
15 public void onCreate(){
16 super.onCreate();
17 currentsong = 0;
18 Log.i("Info", "onCreate");
19 playSong(currentsong);
20 }
21
22 @Override
23 public void onDestroy(){
24 player.stop();
25 player.release();
26 }
27
28 void playSong(int res){
29 player = MediaPlayer.create(this, song[res]);
30 player.start();
31 player.setOnCompletionListener(new OnCompletionListener() {
32 public void onCompletion(MediaPlayer arg0){
33 player.release();
34 nextSong();
35 }
36 });
37 }
38
39 private void nextSong(){
40 if (++currentsong >= song.length) {
41 currentsong = 0;
42 playSong(currentsong);
43 } else {
44 playSong(currentsong);
45 }
46 }
47/*
48 public class MyBinder extends Binder {
49 BGMS getService() {
50 return BGMS.this;
51 }}
52 */
53 private final MSint.Stub mBinder = new MSint.Stub(){
54
55 public void nextSong() throws DeadObjectException {
56 // TODO Auto-generated method stub
57
58 }
59
60 public void pauseSong() throws DeadObjectException {
61 // TODO Auto-generated method stub
62 if (player != null) {
63 player.pause();}
64 }
65
66 public void startSong() throws RemoteException {
67 // TODO Auto-generated method stub
68 Log.i("Info", "dfg sdf sdf ");
69 playSong(currentsong);
70 }
71 };
72}

Laut Tutorial soll in der Manifest folgendes implmentiert werden. Verstehe jedoch den Intentfiter nicht. <service android:enabled="true"
android:name =".BGMS"
android:process=":MSint">
<action android:name="android.test.musicaidl.MSint"></action>
</service>
1

— geändert am 10.05.2012, 17:10:39

Antworten