×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Apr 2003
    Location
    Kiev, Ukraine
    Posts
    49

    MP3 playback: CRASH (w/o exception) when player is closed during prefetch

    Same issue happens not regularly on Nokia N95, Nokia E51, Nokia E71.. Seems to be critical issue: midlet just crashes without errors or exceptions (I am sure on this since all of the places are covered with catching Throwable exceptions and logging).

    MMAPI.Player is created using HTTP URL pointing to remote MP3 file.
    The user wants suddenly to stop the prefetching process (started with player.prefetch()) - for example to change the song or do something else - calling player.close() from some thread may lead to application CRASH!

    Already tried to stop the player first and later player.close() - same issue is reproducible..

    Is there any reliable and SAFE way to close MMAPI.Player when the latter is being prefetched???

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: MP3 playback: CRASH (w/o exception) when player is closed during prefetch

    I'm not surprised this is a problem. The way to do it is: wait until it's prefetched before trying to change its state again. Use a PlayerListener to do this.

    If you're fetching a large amount of data from a remote source, I suggest you realize() the player before prefetching it. Use a PlayerListener to detect the end of the realize process, then prefetch() or close() it, depending on situation. You may be able to realize() more Players than you can prefetch().

    Graham.

  3. #3
    Registered User
    Join Date
    Apr 2003
    Location
    Kiev, Ukraine
    Posts
    49

    Re: MP3 playback: CRASH (w/o exception) when player is closed during prefetch

    Hi, Graham.
    Thanks for the answer.

    Quote Originally Posted by grahamhughes View Post
    I'm not surprised this is a problem. The way to do it is: wait until it's prefetched before trying to change its state again.
    Yeah, to bypass the situation this is the only possible solution, but the requirement is to do fast-switching between the songs upon user's request. By the way in case if I leave the prefetch thread working and try to prefetch another song in the same time - MediaException ("prefetch error -4" - which means No Memory) occurs pretty often. So it'd be better somehow to stop/cancel prefetch process not to occupy the heap and not to wait for prefetch to finish (it could be minutes depending on the network connection!). Unfortunately I do not see the workaround on this situation so far...

    Quote Originally Posted by grahamhughes View Post
    If you're fetching a large amount of data from a remote source, I suggest you realize() the player before prefetching it. Use a PlayerListener to detect the end of the realize process, then prefetch() or close() it, depending on situation. You may be able to realize() more Players than you can prefetch().
    Yes, but it takes longer for device to prefetch the song than to realize the player, so it usually happens that I rather need to cancel prefetching than detect this situation before prefetching is started.
    Last edited by cryptoalex; 2009-11-19 at 18:08.

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: MP3 playback: CRASH (w/o exception) when player is closed during prefetch

    Quote Originally Posted by cryptoalex View Post
    Yes, but it takes longer for device to prefetch the song than to realize the player, so it usually happens that I rather need to cancel prefetching than detect this situation before prefetching is started.
    Really? I would have expected realize() to take longer (as this involved fetching the data). Remember that a prefetch() on an un-realize()d Player performs an automatic realize(). But, I've been surprised before, so if you've tried both, I'll take your word for it.

    Since most Series 60s can cope with more than one simultaneously prefetched Player (this certainly applies to MIDI players, not sure if it also applies to MP3 players), you might get away with allowing the currently-prefetching player to continue in one thread (and close it when it's finished), while prefetching (or at least, realizing) a second player on another thread. You'll need to cope with a rapid sequence of sound shifts causing an exception (when you can't prefetch any more players).

    Hmmm... did you say it was an HTTP URL? Unless you've managed to achieve some kind of streaming, then the phone will be downloading the entire file before playing starts, so you might be better to download the file into a byte[], and then play that (or not). Beware that, on some phones, you will hit a limit to the number of simultaneously active HttpConnections. Well, probably all phones - the limit will be at least 64 on Series 60s, but could be as low as eight on Series 40.

    Graham.

  5. #5
    Registered User
    Join Date
    Apr 2003
    Location
    Kiev, Ukraine
    Posts
    49

    Re: MP3 playback: CRASH (w/o exception) when player is closed during prefetch

    Quote Originally Posted by grahamhughes View Post
    Really? I would have expected realize() to take longer (as this involved fetching the data). Remember that a prefetch() on an un-realize()d Player performs an automatic realize(). But, I've been surprised before, so if you've tried both, I'll take your word for it.
    Well, the problem is with a long-running call. Not a big issue of the nature of this call: realize or prefetch, but the issue is in inability of application developer to cancel the call asynchronously. I think of this problem as of an important issue which is somehow still present in the latest firmwares and KVMs.

    Quote Originally Posted by grahamhughes View Post
    Since most Series 60s can cope with more than one simultaneously prefetched Player (this certainly applies to MIDI players, not sure if it also applies to MP3 players), you might get away with allowing the currently-prefetching player to continue in one thread (and close it when it's finished), while prefetching (or at least, realizing) a second player on another thread. You'll need to cope with a rapid sequence of sound shifts causing an exception (when you can't prefetch any more players).
    This is what I already did, but as I mentioned in the previous post this may lead to NoMemory exception thrown by MMAPI as MediaException with "-4" code (why not to throw OutOfMemory here by the way, Nokia?) because we'll have two simultaneous prefetching threads (and I have already reproduced this exception pretty easily).

    Quote Originally Posted by grahamhughes View Post
    Hmmm... did you say it was an HTTP URL? Unless you've managed to achieve some kind of streaming, then the phone will be downloading the entire file before playing starts, so you might be better to download the file into a byte[], and then play that (or not). Beware that, on some phones, you will hit a limit to the number of simultaneously active HttpConnections. Well, probably all phones - the limit will be at least 64 on Series 60s, but could be as low as eight on Series 40.
    Graham.
    You are right on the fact that Nokia device will download the entire file when prefetch is called. By the way (sorry Nokia) SE device (SE K850, if to talk about the model I saw this behavior) uses buffering approach to play HTTP media instead of buffering 100% of the file like on Nokia device.
    I think it is an idea to make a different approach for Nokia device (SE behaves better with the current approach) and to make manual prefetching to external file and to cancel the download if requested by user. However, if the thread will reach the prefetch call on the local file created up to the time of user's request, we'll still have the same issue.

    Thanks for the answers, Graham.

  6. #6
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: MP3 playback: CRASH (w/o exception) when player is closed during prefetch

    Ultimately, your problem is that there is no way to terminate a blocking operation. This will be true also of reading from an HttpConnection (where, again, the entire response will be downloaded before you have a chance to handle it).

    If the server is under your control, you could build some mechanism for splitting the file into a series of chunks, and download them separately. (You might even be able to specify "Range: bytes=start-end" in the header, most HTTP servers will support this, but it might not get through a proxy.) Then you can at least abort the process sooner. If you organize it correctly, you should be able to discard all the data that's been downloaded so far (minus the currently-downloading chunk) immediately, and avoid OutOfMemory problems.

    Sorry, I can't give you a definitive fix, but I hope this helps a little.

    Graham.

  7. #7
    Registered User
    Join Date
    Apr 2003
    Location
    Kiev, Ukraine
    Posts
    49

    Re: MP3 playback: CRASH (w/o exception) when player is closed during prefetch

    Quote Originally Posted by grahamhughes View Post
    Ultimately, your problem is that there is no way to terminate a blocking operation. This will be true also of reading from an HttpConnection (where, again, the entire response will be downloaded before you have a chance to handle it).
    Are you sure? What makes you think so about HttpConnection? I wrote a small test where a connection was created to read a big MP3 file (about 8 MBs): InputStream was opened pretty fast (sure that it didn't read all 8 MBs in one shot), after that I started to read from the stream and could cancel the reading asynchronously without a problem by closing the InputStream. No crash, seems to work smoothly.

    Quote Originally Posted by grahamhughes View Post
    Sorry, I can't give you a definitive fix, but I hope this helps a little.
    Thanks anyway, I will head the way with manual prefetching instead of MMAPI's remote prefetching.

    But, still, if Nokia has seen this topic, please do something with asynchronous closing of Player, this is really necessary. Let it work like with InputStream closing. Let the prefetch() throw MediaException if player was closed asynchronously. But do not force the developers to wait for prefetch to finish.

  8. #8
    Nokia Developer Champion
    Join Date
    Apr 2007
    Posts
    2,708

    Re: MP3 playback: CRASH (w/o exception) when player is closed during prefetch

    after that I started to read from the stream and could cancel the reading asynchronously without a problem by closing the InputStream. No crash, seems to work smoothly.
    That's why Graham was talking about the HttpConnection not the InputStream... those two aren't the same, you can create a httpConnection object and attach an InputStream to it... Still if you close the InputStream that doesn't mean you are closing the HtppConnection...

  9. #9
    Registered User
    Join Date
    Apr 2003
    Location
    Kiev, Ukraine
    Posts
    49

    Re: MP3 playback: CRASH (w/o exception) when player is closed during prefetch

    Quote Originally Posted by Tiger79 View Post
    That's why Graham was talking about the HttpConnection not the InputStream... those two aren't the same, you can create a httpConnection object and attach an InputStream to it...
    But the issue is to stop/cancel/break the long running procedure (like realize/prefetch in MMAPI). If we talk about manual data prefetching with HttpConnection: What is the longer operation: opening HttpConnection or downloading MP3 files with InputStream opened by HttpConnection?

    Quote Originally Posted by Tiger79 View Post
    Still if you close the InputStream that doesn't mean you are closing the HtppConnection...
    I break the reading(realizing/prefetching) without application crash - this is the result I can't achieve with MMAPI! And after closing InputStream I can close HttpConnection of course.

Similar Threads

  1. Create 3GP player with J2ME for Mobile
    By dexxa05 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 57
    Last Post: 2012-01-10, 11:44
  2. mp3 file download as .aspx file and not open on phone player
    By yogendratrivedi in forum Mobile Web Site Development
    Replies: 6
    Last Post: 2007-12-06, 09:53
  3. VS.Net 2003 Carbide 2.01 and epoc32.exe
    By ValentinK in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 2
    Last Post: 2007-01-12, 12:31
  4. How to avoid "Connection closed during transmission" -exception?
    By anummiah in forum Mobile Java Tools & SDKs
    Replies: 2
    Last Post: 2004-12-31, 21:00
  5. can not successfully link any sample using .NET
    By lobotomat in forum Symbian Tools & SDKs
    Replies: 2
    Last Post: 2002-08-20, 00:29

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •