×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    18

    What are realize and prefetch exactly ?

    Hi every one
    in the mmapi when u create a player there are two steps that must be done
    1-player.realize().
    2-player.prefetch().

    my question is what are exactly the functions of each of realize and prefetch
    and if i use the player to record video is it necessary to call prefetch each time i record or it is just called once ?

    thanks a lot

  2. #2
    Super Contributor
    Join Date
    Feb 2006
    Posts
    689

    Re: What are realize and prefetch exactly ?

    Hi,
    may this be helpful to you..
    http://www.j2meforums.com/wiki/index...nd_Information
    Thanks
    Soku

  3. #3
    Regular Contributor
    Join Date
    Aug 2006
    Posts
    307

    Re: What are realize and prefetch exactly ?

    Take a look at this document, the MMAPI's Player specification: http://java.sun.com/javame/reference...ia/Player.html

    As it says, "transitioned from UNREALIZED to REALIZED (through the realize() method), the Player performs the communication necessary to locate all of the resources it needs to function (such as communicating with a server or a file system). The realize() method allows an application to initiate this potentially time-consuming process at an appropriate time."

    So, the realize() method is helping to connect to a media file or create a new one in the local file system:

    "A Player is in the REALIZED state when it has obtained the information required to acquire the media resources. Realizing a Player can be a resource and time consuming process. The Player may have to communicate with a server, read a file, or interact with a set of objects. Although a realized Player does not have to acquire any resources, it is likely to have acquired all of the resources it needs except those that imply exclusive use of a scarce system resource, such as an audio device. "

    "Once realized, a Player may still need to perform a number of time-consuming tasks before it is ready to be started. For example, it may need to acquire scarce or exclusive resources, fill buffers with media data, or perform other start-up processing. Calling prefetch on the Player carries out these tasks."

    I guess this explained the meanings of the realize() and prefetch() methods.

    The Player itself acts as the state machine, so calling start() immediatelly after player's initialization will invoke realize() and prefetch() methods, in order to correctly transfer from UNREALIZED to the STARTED state.

    The player's instance usually is created for one media file, so switching to another media file also will require prefetching once again for that media file, etc.

  4. #4
    Registered User
    Join Date
    Feb 2007
    Posts
    17

    Re: What are realize and prefetch exactly ?

    i know there is a method Player.deallocate();
    if i call
    Player.start();
    Player.deallocate();
    nothing is played.

    i want to Deallocate the resource once i have played the sound. How do i know the sound has been played and i can then call Player.deallocate(); ??

  5. #5
    Regular Contributor
    Join Date
    Aug 2006
    Posts
    307

    Re: What are realize and prefetch exactly ?

    Quote Originally Posted by singh.jagatjit
    i know there is a method Player.deallocate();
    if i call
    Player.start();
    Player.deallocate();
    nothing is played.

    i want to Deallocate the resource once i have played the sound. How do i know the sound has been played and i can then call Player.deallocate(); ??
    The deallocate() method actually "resets" the player if it was prefetched. Try to use a PlayerListener with the player, so the player will notify you whenever it has finished the media playback through the method playerUpdate(Player player, String event, Object eventData). Usually the END_OF_MEDIA event is thrown at the end of media playback.

    Code:
    Player player;
    
    
    private void startPlayer() {
    
        player = Manager.createPlayer(...);
    
        player.addPlayerListener(this); // note, this class should implement the PlayerListener interface
    
        player.prefetch();
    
        player.start(); // and nothing else
    
    } // end startPlayer
    
    
    ...in the same class...
    
    
    public void playerUpdate(Player player, String event, Object eventData) {
    
        if (event.equals(PlayerListener.END_OF_MEDIA)) {
    
            player.close(); // finito lá comedia
    
            player = null;
    
        } // end if END_OF_MEDIA
    
    } // end playerUpdate
    Last edited by axs; 2007-06-15 at 07:11.

  6. #6
    Registered User
    Join Date
    Feb 2007
    Posts
    17

    Re: What are realize and prefetch exactly ?

    Thank you .. that solves my issue..Much appreciated!
    I have few more questions related to this.


    I have a Sound Engine class which is Listener to events and based on those special events the specific type of sound is played.

    question 1)It could be a possibility when different events play different sounds at the same time. do u recommend me to have one player object or different player objects for different sounds?

    question 2)Other question is, In our application we have to keep memory to the minimum. So i when a specific sound has to be played i create the player, realize it, prefetch it, start it.. and after the sound is played i close it. And when this sound has to be played again the same process is repeated again. How efficient do u think this is in terms of processing?

    Question 2.1)If it takes lot of processing. Do u recommend me that instead of closing the player i deallocate it when it reaches the Prefetched state so that it comes into realized state again. when i want to the play the sound again i prefetch it and start it?

  7. #7
    Regular Contributor
    Join Date
    Aug 2006
    Posts
    307

    Re: What are realize and prefetch exactly ?

    Quote Originally Posted by singh.jagatjit
    question 1)It could be a possibility when different events play different sounds at the same time. do u recommend me to have one player object or different player objects for different sounds?
    It's not quite clear from the question are the "different sounds" meaning two different files, or two different formats, but MMAPI's principles are very simple: one player per one media file; and no troubles for playing supported media formats.

    Take a look at this document from Nokia which explains all aspects of MMAPI, the Mobile Media API Developer's Guide v2.1: http://www.forum.nokia.com/info/sw.n..._1_en.pdf.html

    In this document you'll find information about players pooling, when you'll need to prepare many players to play different files. Also the audio mixing is explaind there (whenever the mobile platform is able to play two (or more) audio files at the same time, in parallel).



    Quote Originally Posted by singh.jagatjit
    question 2)Other question is, In our application we have to keep memory to the minimum. So i when a specific sound has to be played i create the player, realize it, prefetch it, start it.. and after the sound is played i close it. And when this sound has to be played again the same process is repeated again. How efficient do u think this is in terms of processing?
    The MMAPI is hiding from the developer how the media processing happens and how much memory the mobile Java utilizes for the playbacking. The developer cannot affect anyhow on buffer sizes and media data processings, since mobile platform does the actual work, but there are some technical issues which should be taken in account, depending on the mobile platform you're working with. (For example, some S40 mobile platforms cannot play big media files, etc.) That's for memory usages, and so on.

    If you want to play the same file N times, there is no need to recreate the Player N times. Use the Player's method "setLoopCount(int N)" and it will play your content N times.



    Quote Originally Posted by singh.jagatjit
    Question 2.1)If it takes lot of processing. Do u recommend me that instead of closing the player i deallocate it when it reaches the Prefetched state so that it comes into realized state again. when i want to the play the sound again i prefetch it and start it?
    If you were meaning the audio file looping, than there is "setLoopCount(int N)" method.

  8. #8
    Registered User
    Join Date
    Feb 2007
    Posts
    17

    Re: What are realize and prefetch exactly ?

    sorry for the ambiguous questions and thanks for your help.

Similar Threads

  1. prefetch error: -5
    By sepi1982 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 8
    Last Post: 2010-12-12, 10:41
  2. Failed to Prefetch
    By aztec30 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2006-09-25, 17:50
  3. how to decrease prefetch time???
    By desijatt in forum Mobile Java Media (Graphics & Sounds)
    Replies: 3
    Last Post: 2006-09-15, 17:54

Posting Permissions

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