Hi, try by creating media player in different thread
On Sun, Sep 6, 2009 at 3:29 PM, Ludvig Svenonius <[email protected] > wrote: > > I have a rather mysterious problem with the simple test application > below... > > package com.example.helloandroid; > > import android.app.Activity; > import android.media.MediaPlayer; > import android.os.Bundle; > import android.widget.ArrayAdapter; > import android.widget.LinearLayout; > import android.widget.ListView; > import android.widget.TextView; > > public class HelloAndroid extends Activity { > static final String[] LIST_ITEMS = new String[] { > "Item 1", > "Item 2", > "Item 3", > "Item 4", > "Item 5", > etc etc... > }; > > /** Called when the activity is first created. */ > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > > final LinearLayout root = new LinearLayout(this); > root.setOrientation(LinearLayout.VERTICAL); > > final TextView tv = new TextView(this); > > final ListView lv = new ListView(this); > lv.setAdapter(new ArrayAdapter<String>(this, > android.R.layout.simple_list_item_1, LIST_ITEMS)); > > root.addView(tv); > root.addView(lv); > > MediaPlayer mp = new MediaPlayer(); > String msg = ""; > > try { > String path = "/sdcard/MP3/an_mp3_track.MP3"; > > mp.setDataSource(path); > mp.prepare(); > mp.start(); > } > catch (Exception e) { > msg = e.getClass().getName(); > } > > tv.setText(msg); > > setContentView(root); > } > } > > > As you might see from examining the code, it sets up a very simple > layout, consisting of a TextView to display a text message above a > ListView displaying a number of strings. The application also > instantiates a MediaPlayer and begins playback of an mp3 track on the > SD card. So far everything works; the interface will be displayed > correctly and playback of the track will begin... and left on its own > it will keep working. However, if you start fiddling with the ListView > - scrolling it or tapping its items, for example - it may cause the > mp3 playback to suddenly be interrupted, for no apparent reason > whatsoever. The interruption doesn't seem to be caused by a standard > MediaPlayer error, as I've tried registering an OnErrorListener to the > media player and its methods don't seem to be called at the > interruption. I'm running the application on my retail HTC Hero. > > I'm very new to Android development so it's entirely possible that I'm > overlooking something many would consider obvious; however the > symptoms of the problem seem to suggest otherwise: this behaviour is > just weird. Why should user interface components interfere in any way > with a media player, unless designed to do so? > > Thankful for any suggestions, > > Ludvig Svenonius > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

