Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    7

    how can I play the song repeatly and stop playing the song?

    Hi, I would like to ask 2 questions.

    1) how can I stop playing the song when I change from one canvas to another canvas? I want the song stop playing when I press OK or back command in the mobile phone simulator. Actually, I have tried the player.stop(), but it fails to stop playing the song. How can I do this?
    The following is the related coding for playing audio part.

    public class FeedPetCanvas extends Canvas implements CommandListener
    {
    .....
    private Player player;
    ....
    public FeedPetCanvas(MobilePet top, Display display, MobilePetCanvas game, boolean not_eat, int type){
    .....
    loadAudio();
    }

    // play the song
    private void loadAudio(){
    try {
    InputStream in = getClass().getResourceAsStream ("/Food/mcdonald.mid");
    Player player = Manager.createPlayer(in, "audio/midi");
    player.realize();
    player.prefetch();
    player.start();
    }
    catch (Exception e) {
    return;
    }
    }
    // handle the OK and BACK command
    public void commandAction(Command c, Displayable d){
    if(c == okCmd){
    top.enterGame();
    }
    if(c == backCmd){
    top.enterGame();
    }
    }
    }

    2) How can I play the sony repeatly??


    Thanks~~~

  2. #2
    Super Contributor
    Join Date
    Mar 2006
    Posts
    516

    Re: how can I play the song repeatly and stop playing the song?

    Hi Vinnag,

    1) It should work player.stop() should work properly. which is the phone & emulator u r testing? Plz also could u try player.stop()

    2) player.setLoopCount(-1) will play the song indefinetly. Refer the api docs for more explanation

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    7

    Re: how can I play the song repeatly and stop playing the song?

    Thanks for your reply, Wang Shui.
    I have tried player.stop(); But it fails to stop playing the song. What is the problem in my code?

    private void loadAudio(){
    try {
    InputStream in = getClass().getResourceAsStream("/Food/mcdonald.mid");
    Player player = Manager.createPlayer(in, "audio/midi");
    player.setLoopCount(-1);
    player.realize();
    player.prefetch();
    player.start();
    }
    catch (Exception e) {
    return;
    }
    }

    public void commandAction(Command c, Displayable d){
    if(c == okCmd){
    System.out.println("OK pressed");
    try {
    System.out.println("inside try stop");
    player.realize();
    player.prefetch();
    player.stop();
    }
    catch (Exception e) {
    return;
    }
    top.enterGame();
    }
    if(c == backCmd){
    System.out.println("back pressed !!");
    try {
    System.out.println("inside try stop");
    player.realize();
    player.prefetch();
    player.stop();
    }
    catch (Exception e) {
    return;
    }
    top.enterGame();
    }
    }

  4. #4
    Super Contributor
    Join Date
    Nov 2003
    Location
    Bangalore , India
    Posts
    4,430

    Re: how can I play the song repeatly and stop playing the song?

    Hi Vinnahang! Welcome to Nokia Discussion Boards!!

    Please give a try with removing player.realize(); and player.prefetch(); before calling
    player.stop();

    Regards
    Gopal

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    7

    Re: how can I play the song repeatly and stop playing the song?

    Thanks for the reply, I can stop the song now. THZZZZ

  6. #6
    Registered User
    Join Date
    Nov 2011
    Location
    ahmedabad
    Posts
    32

    Re: how can I play the song repeatly and stop playing the song?

    have you got the solution for http://www.developer.nokia.com/Commu...772#post887772

    Thanks
    Jigar

Similar Threads

  1. problem when stop playing video on 3650 and try to play again
    By niko86 in forum Mobile Java General
    Replies: 5
    Last Post: 2007-08-03, 07:40
  2. Major problem with delegation to Canvas
    By bartekn in forum Mobile Java Media (Graphics & Sounds)
    Replies: 8
    Last Post: 2003-10-08, 17:46
  3. How to change screen from canvas?
    By lightpop in forum Mobile Java Media (Graphics & Sounds)
    Replies: 4
    Last Post: 2003-08-07, 13:04
  4. Stop audio playing
    By walterzcm in forum Mobile Java General
    Replies: 0
    Last Post: 2002-12-03, 04:39
  5. Change the paintable canvas size of the emulator
    By Nokia_Archived in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2002-05-17, 18:07

Posting Permissions

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