MediaPlayer & seek on startup

by David Given » Thu, 27 Nov 2008 06:56:22 GMT


Sponsored Links
 I'm trying to play streaming music. The user has previously requested
that the stream start a certain way into the stream. How do I do this?

What I'm finding is that if I do:

mediaplayer.setDataSource(...);
mediaplayer.prepare();
mediaplayer.seekTo(...);

...then the seek happens *after* the initial buffer is read, which of
course is a waste [*]. But if I do:

mediaplayer.setDataSource(...);
mediaplayer.seekTo(...);
mediaplayer.prepare();

...then of course I get an IllegalStateException because the MediaPlayer
hasn't been prepared yet!

Has anyone managed to make anything like this work?



[*] Actually, of course, I'm using prepareAsync(). In fact, what I'm
observing is that calling seekTo() from the onPrepared() callback tends
to confuse MediaPlayer and it hands me a -38 error and I have to reset
and start again. It seems to only want to seek after the playback has
had a chance to settle for a few moments.

-- 
€€  €€€€€  http://www.cowlark.com  €€€€€
,S3=T)=T+/(Vquot;),(Vquot;M),(V,)quot;(V,V)quot;)'
--- Conway's Game Of Life, in one line of APL



MediaPlayer & seek on startup

by Dave Sparks » Thu, 27 Nov 2008 08:13:33 GMT


 You must always call prepare() before seekTo(). The player engine
needs to read the first part of the stream to identify the stream type
and required codecs and read the content index (if it exists).



--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


MediaPlayer & seek on startup

by David Given » Thu, 27 Nov 2008 22:30:09 GMT


 


Well, yes, I'm aware of that. However, it doesn't just read the stream
header, it spends 10-15 seconds buffering the initial stream. This is
leading to a really poor user experience, as the user has to wait (and
pay) for the first part of the stream to be buffered --- then the seek
happens, it all gets thrown away, and the user has to wait (and pay) for
*another* 10-15 seconds while the buffer gets filled from the correct
location.

Is there any way of streamlining this? Can I tell MediaPlayer to *just*
read the metadata and not to try and fill the buffer, for example?

-- 
David Given
[EMAIL PROTECTED]

--~--~---------~--~----~------------~-------~--~----~



MediaPlayer & seek on startup

by David Given » Sat, 29 Nov 2008 05:23:04 GMT


 

[...]

Does anyone have any suggestions on how do this? If I can't make this
work, my app is basically stuffed, and nothing I've tried is working.

Brief summary: I need to be able to tell MediaPlayer to start playing
from somewhere in the middle of the stream, not the start. If I call
seekTo() after prepare() then the user has to wait for the buffer to be
filled twice, which can take up to thirty seconds, and they're not going
to put up with that.

Is there a way to tell it to prepare the stream (reading the stream
header, etc) but *not* to fill the buffer until I tell it to start
playing? That would work.

-- 
€€  €€€€€  http://www.cowlark.com  €€€€€
,S3=T)=T+/(Vquot;),(Vquot;M),(V,)quot;(V,V)quot;)'
--- Conway's Game Of Life, in one line of APL



MediaPlayer & seek on startup

by Dave Sparks » Tue, 02 Dec 2008 01:14:41 GMT


 I can't think of any alternative solution at this time. The code that
handles this is in the OpenCore engine and not something you can
address with a Java API.

Perhaps this is something we can address in a future release.





--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. ListView problem - items are shrank when while scrolling the view

Hi,

I found strange behavior in ListView.
I have ListView of TextView except from one entry that contains
ImageView.
when i on of the items is touched and scroll up and down the image is
re-sized to about 2/3 its original size! Usually, the image remains in
this smaller size when the user lifts his finger and stops scrolling.
The original size can be restored by tapping your finger on any of the
empty list cells.

any idea?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
        xmlns:app="http://schemas.android.com/apk/res/com.jumptap.test"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    >

        <ListView
                android:id="@+id/myList"
                        android:layout_width="fill_parent"
                        android:layout_height="300dip"/>
</RelativeLayout>

ListView lv = (ListView)findViewById(R.id.myList);
                lv.setAdapter(new BaseAdapter() {

                        @Override
                        public View getView(int position, View convertView, 
ViewGroup
parent) {

                                if (position==5) {
                                        return imgView;
                                } else {
                                        TextView tv = new 
TextView(TestActivity.this);
                                        tv.setText("Entry #"+position);
                                        tv.setMinimumHeight(50);
                                        tv.setBackgroundColor(Color.DKGRAY);
                                        return tv;
                                }
                        }

                        @Override
                        public long getItemId(int position) {
                                // TODO Auto-generated method stub
                                return position;
                        }

                        @Override
                        public Object getItem(int position) {
                                // TODO Auto-generated method stub
                                return null;
                        }

                        @Override
                        public int getCount() {
                                return 15;
                        }
                });


-- 

2. aPad/iRobot 2nd generation bisa disambung ke 3G/HSPA USB dongl

Kabar terbaru, sudah positif bisa disambung ke beberapa modem USB
(Huawei EG162G dan Vtion e1916! )
Secara otomatis setelah disambungkan, nanti akan muncul dialer
software untuk dial ke modemnya. Keren!!!!!

Kalo ada yang punya USB modem dan aPAD, dipersilahkan untuk
mencoba...saya gak punya USB modem :(
Kalo sukses, please report yah modem apa aja yang mumpuni.

Thanks!!!

-- 
"Indonesian Android Community [id-android]" 

3. Class ServiceManager missing in Android 2.1

4. Latency due to Garbage collection on onPrevFrame

5. IM Native..again....

6. How to apply background color to all the activities

7. Clearing all the Task within an application while activity launch