Re: [android-developers] VideoView and buffering

2012-01-31 Thread John-Marc Desmarais
Daniel,

It is my feeling that since the swap is being done in the onCompletion
handler, there would be a gap in playback in either case. If prepare
is the time consuming part of Prepare(), Start(), Seekto().. then I
can see this shrinking the gap. But, if there is a detectable delay,
then the length of this delay is of lesser concern. If I get the time
to go back to this component when I'm done some other bits, I'll let
you know how it turns out.

I find it odd that the VideoView screen doesn't ever re-read from the
file. I've tried buffering 1MB or 2MB before starting to play, but it
still doesn't go back to the file to read more data, I'm guessing it
loads all 2MB into memory before starting to play. I'll try some
bigger buffer sizes as well to see if I can force it to reread before
the video runs out.

-jm

On Tue, Jan 31, 2012 at 11:08 AM, Daniel Drozdzewski
 wrote:
> John-Marc,
>
> I am glad that it works.
>
> I am not sure whether prepareAsync would be quicker than blocking prepare 
> call.
>
> I mean that whatever the system implementation of the player,
> preparing it takes the same amount of time and async call simply does
> not block, but if you call play as a next statement after
> prepareAsync, I think playing will be put on hold until the player is
> ready to play. You could test both approaches by adding some logging
> and swapping these calls to prepare.
>
> I was also thinking that you could create 2 MediaPlayer objects and
> the one that is not playing at the moment is being prepared in the
> background with the new data that arrived.
> In MediaPlayer.OnCompletionListener of the first player you simply
> cause the background, prepared player to swap seats with the one that
> just finished. Maybe that would be a bit smoother... ( I am only
> speculating here). This is simple double buffering used all over
> computers to avoid flickering when displaying moving objects.
>
> Not the easiest approach, but if you are swapping the files from
> underneath 1 player, then swapping players from underneath 1 activity
> should not be much more complex.
>
> Daniel
>
>
>
>
>
>
>
> On 31 January 2012 14:50, John-Marc Desmarais  wrote:
>> Hi,
>>
>> I'm using the reset() now. There's a little bump in the playback every
>> time it reaches the end of the content that existed in the file when
>> it was initially loaded which I don't like but I'm using prepareAsync
>> so I think this hiccup is as small as I can make it with a single
>> VideoView.
>>
>> Thanks for your help.
>> -jm
>>
>>
>> On Mon, Jan 30, 2012 at 11:16 AM, Daniel Drozdzewski
>>  wrote:
>>> John-Marc,
>>>
>>> I have not done this myself, but here is tutorial on how to do it:
>>> http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/
>>>
>>> They actually create new MediaPlayer object upon every update to the
>>> buffer file and point this new MediaPlayer to the updated buffer every
>>> single time.
>>>
>>> I would test calling MediaPlayer.reset() first instead of creating new
>>> player object every time, to see whether time and memory consumed by
>>> such solution is a bit better.
>>>
>>> HTH,
>>>
>>> Daniel
>>>
>>>
>>>
>>>
>>>
>>> On 30 January 2012 15:49, John-Marc Desmarais  wrote:
 Hi,

 I am currently writing a video file to the SDCard while playing it
 with VideoView.

 My problem is that, if I buffer 1MB of video and begin the Video
 playback, the video stops after 1MB has been played, even though by
 this time, 5MBs of file has now been written to the sdcard.

 I have been trying various things in onCompletion handler.. such as:
                int curLoc = mp.getCurrentPosition();
                Log.e(LogName.onCompletion, LogName.onCompletion + 
 "CurrentLocation:
 " + mp.getCurrentPosition());
                Log.e(LogName.onCompletion, LogName.onCompletion + 
 "Duration: " +
 mp.getDuration());
                mp.pause();
                mp.prepareAsync();
                mp.start();
                mp.seekTo(curLoc);

 In this case I get a "Cannot play video" message.

 Or:
                int curLoc = mp.getCurrentPosition();
                Log.e(LogName.onCompletion, LogName.onCompletion + 
 "CurrentLocation:
 " + mp.getCurrentPosition());
                Log.e(LogName.onCompletion, LogName.onCompletion + 
 "Duration: " +
 mp.getDuration());
                mp.prepareAsync();
                mp.start();
                mp.seekTo(curLoc);

 This crashes with "prepare Async in State 128".

 Has anyone solved the problem of re-queuing file in the videoView so
 that it plays everything that has been written to the sdcard even
 though it starts with a smaller file?

 Regards,
 -jm

 --
 You received this message because you are subscribed to the Google
 Groups "Android Developers" group.
 To post

Re: [android-developers] VideoView and buffering

2012-01-31 Thread Daniel Drozdzewski
John-Marc,

I am glad that it works.

I am not sure whether prepareAsync would be quicker than blocking prepare call.

I mean that whatever the system implementation of the player,
preparing it takes the same amount of time and async call simply does
not block, but if you call play as a next statement after
prepareAsync, I think playing will be put on hold until the player is
ready to play. You could test both approaches by adding some logging
and swapping these calls to prepare.

I was also thinking that you could create 2 MediaPlayer objects and
the one that is not playing at the moment is being prepared in the
background with the new data that arrived.
In MediaPlayer.OnCompletionListener of the first player you simply
cause the background, prepared player to swap seats with the one that
just finished. Maybe that would be a bit smoother... ( I am only
speculating here). This is simple double buffering used all over
computers to avoid flickering when displaying moving objects.

Not the easiest approach, but if you are swapping the files from
underneath 1 player, then swapping players from underneath 1 activity
should not be much more complex.

Daniel







On 31 January 2012 14:50, John-Marc Desmarais  wrote:
> Hi,
>
> I'm using the reset() now. There's a little bump in the playback every
> time it reaches the end of the content that existed in the file when
> it was initially loaded which I don't like but I'm using prepareAsync
> so I think this hiccup is as small as I can make it with a single
> VideoView.
>
> Thanks for your help.
> -jm
>
>
> On Mon, Jan 30, 2012 at 11:16 AM, Daniel Drozdzewski
>  wrote:
>> John-Marc,
>>
>> I have not done this myself, but here is tutorial on how to do it:
>> http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/
>>
>> They actually create new MediaPlayer object upon every update to the
>> buffer file and point this new MediaPlayer to the updated buffer every
>> single time.
>>
>> I would test calling MediaPlayer.reset() first instead of creating new
>> player object every time, to see whether time and memory consumed by
>> such solution is a bit better.
>>
>> HTH,
>>
>> Daniel
>>
>>
>>
>>
>>
>> On 30 January 2012 15:49, John-Marc Desmarais  wrote:
>>> Hi,
>>>
>>> I am currently writing a video file to the SDCard while playing it
>>> with VideoView.
>>>
>>> My problem is that, if I buffer 1MB of video and begin the Video
>>> playback, the video stops after 1MB has been played, even though by
>>> this time, 5MBs of file has now been written to the sdcard.
>>>
>>> I have been trying various things in onCompletion handler.. such as:
>>>                int curLoc = mp.getCurrentPosition();
>>>                Log.e(LogName.onCompletion, LogName.onCompletion + 
>>> "CurrentLocation:
>>> " + mp.getCurrentPosition());
>>>                Log.e(LogName.onCompletion, LogName.onCompletion + 
>>> "Duration: " +
>>> mp.getDuration());
>>>                mp.pause();
>>>                mp.prepareAsync();
>>>                mp.start();
>>>                mp.seekTo(curLoc);
>>>
>>> In this case I get a "Cannot play video" message.
>>>
>>> Or:
>>>                int curLoc = mp.getCurrentPosition();
>>>                Log.e(LogName.onCompletion, LogName.onCompletion + 
>>> "CurrentLocation:
>>> " + mp.getCurrentPosition());
>>>                Log.e(LogName.onCompletion, LogName.onCompletion + 
>>> "Duration: " +
>>> mp.getDuration());
>>>                mp.prepareAsync();
>>>                mp.start();
>>>                mp.seekTo(curLoc);
>>>
>>> This crashes with "prepare Async in State 128".
>>>
>>> Has anyone solved the problem of re-queuing file in the videoView so
>>> that it plays everything that has been written to the sdcard even
>>> though it starts with a smaller file?
>>>
>>> Regards,
>>> -jm
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Android Developers" group.
>>> To post to this group, send email to android-developers@googlegroups.com
>>> To unsubscribe from this group, send email to
>>> android-developers+unsubscr...@googlegroups.com
>>> For more options, visit this group at
>>> http://groups.google.com/group/android-developers?hl=en
>>
>>
>>
>> --
>> Daniel Drozdzewski
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to android-developers@googlegroups.com
>> To unsubscribe from this group, send email to
>> android-developers+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> h

Re: [android-developers] VideoView and buffering

2012-01-31 Thread John-Marc Desmarais
Hi,

I'm using the reset() now. There's a little bump in the playback every
time it reaches the end of the content that existed in the file when
it was initially loaded which I don't like but I'm using prepareAsync
so I think this hiccup is as small as I can make it with a single
VideoView.

Thanks for your help.
-jm


On Mon, Jan 30, 2012 at 11:16 AM, Daniel Drozdzewski
 wrote:
> John-Marc,
>
> I have not done this myself, but here is tutorial on how to do it:
> http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/
>
> They actually create new MediaPlayer object upon every update to the
> buffer file and point this new MediaPlayer to the updated buffer every
> single time.
>
> I would test calling MediaPlayer.reset() first instead of creating new
> player object every time, to see whether time and memory consumed by
> such solution is a bit better.
>
> HTH,
>
> Daniel
>
>
>
>
>
> On 30 January 2012 15:49, John-Marc Desmarais  wrote:
>> Hi,
>>
>> I am currently writing a video file to the SDCard while playing it
>> with VideoView.
>>
>> My problem is that, if I buffer 1MB of video and begin the Video
>> playback, the video stops after 1MB has been played, even though by
>> this time, 5MBs of file has now been written to the sdcard.
>>
>> I have been trying various things in onCompletion handler.. such as:
>>                int curLoc = mp.getCurrentPosition();
>>                Log.e(LogName.onCompletion, LogName.onCompletion + 
>> "CurrentLocation:
>> " + mp.getCurrentPosition());
>>                Log.e(LogName.onCompletion, LogName.onCompletion + "Duration: 
>> " +
>> mp.getDuration());
>>                mp.pause();
>>                mp.prepareAsync();
>>                mp.start();
>>                mp.seekTo(curLoc);
>>
>> In this case I get a "Cannot play video" message.
>>
>> Or:
>>                int curLoc = mp.getCurrentPosition();
>>                Log.e(LogName.onCompletion, LogName.onCompletion + 
>> "CurrentLocation:
>> " + mp.getCurrentPosition());
>>                Log.e(LogName.onCompletion, LogName.onCompletion + "Duration: 
>> " +
>> mp.getDuration());
>>                mp.prepareAsync();
>>                mp.start();
>>                mp.seekTo(curLoc);
>>
>> This crashes with "prepare Async in State 128".
>>
>> Has anyone solved the problem of re-queuing file in the videoView so
>> that it plays everything that has been written to the sdcard even
>> though it starts with a smaller file?
>>
>> Regards,
>> -jm
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Android Developers" group.
>> To post to this group, send email to android-developers@googlegroups.com
>> To unsubscribe from this group, send email to
>> android-developers+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/android-developers?hl=en
>
>
>
> --
> Daniel Drozdzewski
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] VideoView and buffering

2012-01-30 Thread Daniel Drozdzewski
John-Marc,

I have not done this myself, but here is tutorial on how to do it:
http://blog.pocketjourney.com/2008/04/04/tutorial-custom-media-streaming-for-androids-mediaplayer/

They actually create new MediaPlayer object upon every update to the
buffer file and point this new MediaPlayer to the updated buffer every
single time.

I would test calling MediaPlayer.reset() first instead of creating new
player object every time, to see whether time and memory consumed by
such solution is a bit better.

HTH,

Daniel





On 30 January 2012 15:49, John-Marc Desmarais  wrote:
> Hi,
>
> I am currently writing a video file to the SDCard while playing it
> with VideoView.
>
> My problem is that, if I buffer 1MB of video and begin the Video
> playback, the video stops after 1MB has been played, even though by
> this time, 5MBs of file has now been written to the sdcard.
>
> I have been trying various things in onCompletion handler.. such as:
>                int curLoc = mp.getCurrentPosition();
>                Log.e(LogName.onCompletion, LogName.onCompletion + 
> "CurrentLocation:
> " + mp.getCurrentPosition());
>                Log.e(LogName.onCompletion, LogName.onCompletion + "Duration: 
> " +
> mp.getDuration());
>                mp.pause();
>                mp.prepareAsync();
>                mp.start();
>                mp.seekTo(curLoc);
>
> In this case I get a "Cannot play video" message.
>
> Or:
>                int curLoc = mp.getCurrentPosition();
>                Log.e(LogName.onCompletion, LogName.onCompletion + 
> "CurrentLocation:
> " + mp.getCurrentPosition());
>                Log.e(LogName.onCompletion, LogName.onCompletion + "Duration: 
> " +
> mp.getDuration());
>                mp.prepareAsync();
>                mp.start();
>                mp.seekTo(curLoc);
>
> This crashes with "prepare Async in State 128".
>
> Has anyone solved the problem of re-queuing file in the videoView so
> that it plays everything that has been written to the sdcard even
> though it starts with a smaller file?
>
> Regards,
> -jm
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en



-- 
Daniel Drozdzewski

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] VideoView and buffering

2012-01-30 Thread John-Marc Desmarais
Hi,

I am currently writing a video file to the SDCard while playing it
with VideoView.

My problem is that, if I buffer 1MB of video and begin the Video
playback, the video stops after 1MB has been played, even though by
this time, 5MBs of file has now been written to the sdcard.

I have been trying various things in onCompletion handler.. such as:
int curLoc = mp.getCurrentPosition();
Log.e(LogName.onCompletion, LogName.onCompletion + 
"CurrentLocation:
" + mp.getCurrentPosition());
Log.e(LogName.onCompletion, LogName.onCompletion + "Duration: " 
+
mp.getDuration());
mp.pause();
mp.prepareAsync();
mp.start();
mp.seekTo(curLoc);

In this case I get a "Cannot play video" message.

Or:
int curLoc = mp.getCurrentPosition();
Log.e(LogName.onCompletion, LogName.onCompletion + 
"CurrentLocation:
" + mp.getCurrentPosition());
Log.e(LogName.onCompletion, LogName.onCompletion + "Duration: " 
+
mp.getDuration());
mp.prepareAsync();
mp.start();
mp.seekTo(curLoc);

This crashes with "prepare Async in State 128".

Has anyone solved the problem of re-queuing file in the videoView so
that it plays everything that has been written to the sdcard even
though it starts with a smaller file?

Regards,
-jm

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en