×

Discussion Board

Results 1 to 13 of 13
  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    22

    Exclamation play mp3 in background

    Hi all,
    I want to play a mp3 file for 1 minute in background from exe application.
    I do not want any audio player UI for the same.
    Anybody knows how to do it.?


    Thanks in advance.

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: play mp3 in background

    What have you tied so far ?

    in Symbian you can actually do exactly the same as you would do in application which is in foreground.

  3. #3
    Registered User
    Join Date
    Jul 2012
    Posts
    22

    Re: play mp3 in background

    so far i am able to play audio with CPlayerUtility as explained on : http://www.developer.nokia.com/Commu...ng_audio_files
    but i am not able to set the duration for playback.
    I tried to stop player after 1 minute duration with
    RTimer timer.After(timerStatus,duration);
    but it hangs the app.
    Last edited by akshay.raikwar; 2013-02-28 at 14:01. Reason: more info

  4. #4
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: play mp3 in background

    How did you try it ?
    and Which line in your code hangs ?

    In general it should work just fine.

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,737

    Re: play mp3 in background

    (In general it should work just fine, assuming that the timer is realized via an active object. See http://www.developer.nokia.com/Commu...implementation for a short example)

  6. #6
    Registered User
    Join Date
    Jul 2012
    Posts
    22

    Re: play mp3 in background

    I dont know exactly on what line it is hanging but i know following :

    iPlayerUtility->Play();
    this is what i am using for playing file

    RTimer timer;
    TRequestStatus timerStatus;
    timer.CreateLocal();
    timer.After(timerStatus,constantTime);
    User::WaitForRequest(timerStatus);
    iPlayerUtility->Stop();
    If i add this code to stop after 1 min everything hangs i can't access menu also (device e5)

    and the play back starts after timer expiration

  7. #7
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,737

    Re: play mp3 in background

    Make sure you read #5 and implement an active object. The audio player can not work while the code is doing a User::WaitForRequest.

  8. #8
    Registered User
    Join Date
    Jul 2012
    Posts
    22

    Re: play mp3 in background

    Hi Working OK with active objects.
    Thank you very much

    But one more problem i am getting is i want repeat my mp3 file till time duration is reached so i have done

    void CPlayerUtility::MapcPlayComplete(TInt /*aError*/)
    {
    //we want to play it continously repeatedly
    if (iPlaying)
    {
    Play();
    }
    }

    this change in CPlayerUtility clas.

    then audio doesn't play at all

  9. #9
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: play mp3 in background

    You might want to debug and see what parts of your code actually gets executed.

  10. #10
    Registered User
    Join Date
    Jul 2012
    Posts
    22

    Re: play mp3 in background

    One more thing

    My audio is playing in gui application.
    But when i try the same code in exe application then audio doesn't play at all.

    is there something in my code similar to User::WaitForRequest which is blocking my play back ?

    My exe code is :

    // connect to window server
    RWsSession ws;
    User::LeaveIfError(ws.Connect());
    CleanupClosePushL(ws);

    TRequestStatus status;

    // create a window group for the thread
    RWindowGroup wg(ws);
    wg.Construct((TUint32)&wg, EFalse);
    CleanupClosePushL(wg);

    // capture a key
    wg.CaptureKey('0', 0, 0);
    wg.CaptureLongKey('0','0',0,0,0,ELongCaptureNormal);

    // listen for the key presses
    ws.EventReady(&status);

    // hide this window group from the app switcher
    wg.SetOrdinalPosition(-1);
    wg.EnableReceiptOfFocus(EFalse);
    CApaWindowGroupName* wn=CApaWindowGroupName::NewLC(ws);
    wn->SetHidden(ETrue);
    wn->SetWindowGroupName(wg);

    // handle key events

    for(; {
    User::WaitForAnyRequest();
    if (status.Int()==KErrNone) {
    TWsEvent e;
    ws.GetEvent(e);

    TInt c;
    TKeyEvent* aKeyEvent=e.Key();
    c=aKeyEvent->iCode;

    if( e.Key()->iRepeats > 0 )
    {
    {
    CPlayerUtility* iPlayerUtility = CPlayerUtility::NewL();
    //iPlayerUtility->PlayAlarmAndMakeCall();
    iPlayerUtility->Play();

    }
    TInt wgid=ws.GetFocusWindowGroup();
    ws.SendEventToWindowGroup(wgid, e);
    }
    ws.EventReady(&status);

    // stop condition
    }

    // clean up
    ws.EventReadyCancel();
    CleanupStack::PopAndDestroy(3); //ws, wg, wn
    Last edited by akshay.raikwar; 2013-03-01 at 06:32.

  11. #11
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: play mp3 in background

    you should remove all for(; and User::WaitForAnyRequest(); and actually do real active object implementations. currently its impossible to see what would be happening really.

  12. #12
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,737

    Re: play mp3 in background

    Symbian code is single-threaded by nature, and asynchronous events are handled sequentially with active objects. You can get some impressions from http://www.developer.nokia.com/Commu...tive_Scheduler how the events are dispatched.
    If you block that single thread, asynchronous operations can not work. Create active objects for your timer, for your keyboard handler, etc., then start the scheduler loop.

  13. #13
    Registered User
    Join Date
    Jul 2012
    Posts
    22

    Re: play mp3 in background

    Found a work around
    Launching GUI app from exe and getting required work doneand then terminating app.
    Will surely try with active objects as suggested whenever i get time

    Thanks wizard_hu_ and symbianyucca for help

Similar Threads

  1. Play Sound Effect while background sound playing problem
    By subzaku in forum Mobile Java Media (Graphics & Sounds)
    Replies: 3
    Last Post: 2012-02-21, 09:01
  2. Play video in background window
    By Mete in forum Symbian
    Replies: 2
    Last Post: 2009-02-17, 21:33
  3. Can background app play sounds?
    By juliand77 in forum Symbian Media (Closed)
    Replies: 0
    Last Post: 2005-01-27, 12:51
  4. How to play background sound on XHTML pages?
    By kaliliu in forum Browsing and Mark-ups
    Replies: 0
    Last Post: 2004-08-10, 13:32

Posting Permissions

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