×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    224

    Playing AMR file is solved, Here is the solution.

    //I have implemented the AMR playing functionalities in CAudioPlayerEngine class
    //Declaration of required constants
    //I hardcoded the amr file, you could use some file browser or you can get amr data from the descriptor array.
    _LIT(KAmrFile, "\\system\\apps\\AudioPlayer\\test.amr");

    //Cosntants needed for playing the amr file/descriptor
    const TUid KMMFExControllerUID = {0x101F5022};
    const TUid KMMFExDesFormatUID = {0x101FAF66};
    const TUint32 KMMFFourCCCodeAMR = {0x524d4120};

    void CAudioPlayerEngine::ConstructL()
    {
    //Declare "CMdaAudioRecorderUtility* iAmrPlayer" in the header file
    iAmrPlayer = CMdaAudioRecorderUtility::NewL(*this,NULL,EMdaPriorityNormal,EMdaPriorityPreferenceTimeAndQuality);
    }

    void CAudioPlayerEngine::PlayAmrL()
    {
    /*
    This method shows how amr file can be played from the descriptor. AMR file is
    first read from the file to iStreamBuffer which is a TPtr8 to the descriptor data.
    Then OpenDesL method is used to play the file.
    */
    RFs fs;
    CleanupClosePushL(fs); // PUSH
    User::LeaveIfError(fs.Connect());
    RFile file;
    CleanupClosePushL(file); // PUSH
    TFileName streamFile(KAmrFile);
    User::LeaveIfError(CompleteWithAppPath(streamFile));
    User::LeaveIfError(file.Open(fs, streamFile, EFileRead | EFileShareReadersOnly));
    TInt fileSize = 0;
    file.Size(fileSize);
    //Declare in header file "TUint8* iSteamData"
    iStreamData = new (ELeave) TUint8[fileSize];
    //Declare in header file "TPtr8* iStreamBuffer"
    iStreamBuffer = new (ELeave) TPtr8(iStreamData, fileSize, fileSize);
    file.Read(*iStreamBuffer);

    //OpenDesL method opens the amr stored in the descriptor buffer, as soon as the opening completes,
    //MoscoStateChangeEvent(..) callback method is called
    iAmrPlayer->OpenDesL(*iStreamBuffer,KMMFExControllerUID,KMMFExControllerUID,
    KMMFExDesFormatUID,KMMFFourCCCodeAMR);
    CleanupStack::PopAndDestroy(2);

    /*
    This is another method for playing amr file. amr file is directly played from the
    file itself. In both cases CMdaAudioRecorderUtility class is used.
    */

    /*
    TFileName amrFile(KAmrFile);
    User::LeaveIfError(CompleteWithAppPath(amrFile));
    iAmrPlayer->OpenFileL(amrFile,KMMFExControllerUID,KMMFExControllerUID,
    KMMFExDesFormatUID,KMMFFourCCCodeAMR);
    */
    }

    void CAudioPlayerEngine::MoscoStateChangeEvent(CBase* aObject, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
    {
    //Checking the curren state. Current state has to be EOpen and aErrorCode has to be KErrNone.
    if((aErrorCode == KErrNone) && (aCurrentState == iAmrPlayer->EOpen))
    {
    iState = EPlaying;
    iAmrPlayer->PlayL();
    }
    }

    //This is complete solution for handling AMR file, If someone having problem using this code, contact me.

  2. #2
    Registered User
    Join Date
    Jul 2005
    Posts
    41

    Re: Playing AMR file is solved, Here is the solution.

    The soultion can work on emulator and 6600, but fails on 6620,6260,6630,7610.
    The MoscoStateChangeEvent() always gets an error (-1).
    Can you give me more advice?

  3. #3
    Regular Contributor
    Join Date
    Oct 2004
    Location
    india
    Posts
    306

    Re: Playing AMR file is solved, Here is the solution.

    for phones like 6630 ,6680
    initialization of player takes a little delay extra........
    so after calling OpendesL()......delay some time here ...


    since OPenDesL() calls MoscoStateChangeEvent(..) to chk the status of the player//

    bye
    N

  4. #4
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    224

    Re: Playing AMR file is solved, Here is the solution.

    Hi,

    The solution using CMdaAudioRecorderUtility is not a good working solution. I have noticed that too. I use CMdaAudioPlayerUtility to play AMR. But it will not work on Emulator because of MMF plugin missing there. You can play AMR using CMdaAudioPlayerUtility by any phone whose MMF supports AMR or any other codec which you want to play. Follow the following steps. Hope you will get it working.

    I actuall download the amr file over network. You could test it by loading it locally. Just call LoadAmrFile, it will start playing. Take care of all the memory deletion in the destructor. Let me know when you get it working.

    _LIT(KAmrFile, "\\system\\apps\\YourApp\\test.amr");

    void CStreamPlayEngine::LoadAmrFile()
    {
    RFs fs;
    CleanupClosePushL(fs); // PUSH
    User::LeaveIfError(fs.Connect());
    RFile file;
    CleanupClosePushL(file); // PUSH
    TFileName streamFile(KAmrFile);
    User::LeaveIfError(CompleteWithAppPath(streamFile));
    User::LeaveIfError(file.Open(fs, streamFile, EFileRead | EFileShareReadersOnly));
    TInt fileSize = 0;
    file.Size(fileSize);
    //Declare in header file "TUint8* iSteamData"
    iStreamData = new (ELeave) TUint8[fileSize];
    //Declare in header file "TPtr8* iStreamBuffer"
    iStreamBuffer = new (ELeave) TPtr8(iStreamData, fileSize, fileSize);
    file.Read(*iStreamBuffer);
    this->PlayStream(*iStreamBuffer);
    CleanupStack::PopAndDestroy(2);
    }

    void CStreamPlayEngine::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/)
    {
    if (aError == KErrNone)
    {
    streamReady = ETrue;
    TTimeIntervalMicroSeconds rTime(1000000);
    iStreamPlayer->SetRepeats(KMdaRepeatForever,rTime);
    iStreamPlayer->SetPriority(EMdaPriorityMax, EMdaPriorityPreferenceNone);
    SetVolume(iVolume);
    iStreamPlayer->Play();
    }
    else
    {
    Stop();
    }
    }

    void CStreamPlayEngine::MapcPlayComplete(TInt aError)
    {
    if(aError == KErrDied)
    {
    SetengineState(EEngineReady);
    iCallBack->PlayingInterrupted();
    }
    if(aError == KErrInUse)
    {
    iCallBack->Log(_L("Previous open is waiting"));
    }
    }

    void CStreamPlayEngine::PlayStream(const TDesC8& aBuffer)
    {
    iVolume = 5;
    streamReady = EFalse;

    if(!iStreamPlayer)
    {
    iStreamPlayer = CMdaAudioPlayerUtility::NewL(*this);
    }
    else
    {
    iStreamPlayer->Close();
    }

    iStreamPlayer->OpenDesL(aBuffer);
    SetengineState(EEnginePlaying);
    }

    void CStreamPlayEngine::CloseStream()
    {
    if(iStreamPlayer)
    {
    iStreamPlayer->Close();
    streamReady = EFalse;
    }
    }

    void CStreamPlayEngine::SetVolume(TInt aVol)
    {
    iVolume = aVol; //TInt iVolume

    if(iVolume < 0)
    iVolume = 0;
    else if(iVolume > 10)
    iVolume = 10;

    if(iStreamPlayer)
    {
    iStreamPlayer->SetVolume(((iStreamPlayer->MaxVolume() * iVolume) / 10));
    }
    }
    Regards,
    shagor

  5. #5
    Registered User
    Join Date
    Jul 2005
    Posts
    41

    Re: Playing AMR file is solved, Here is the solution.

    Thank you very much! It work! It can play amr file on 6600,6620,6260,7610,6630 and X700.

  6. #6
    Regular Contributor
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    224

    Thumbs up Re: Playing AMR file is solved, Here is the solution.

    Hi Stone,

    The code actually can play AMR on any device whose MMF plugin support AMR stuff.

    Regards,
    shagor
    Regards,
    shagor

  7. #7
    Registered User
    Join Date
    Dec 2005
    Posts
    2

    Re: Playing AMR file is solved, Here is the solution.

    Quote Originally Posted by giridharn
    for phones like 6630 ,6680
    initialization of player takes a little delay extra........
    so after calling OpendesL()......delay some time here ...


    since OPenDesL() calls MoscoStateChangeEvent(..) to chk the status of the player//

    bye
    N


    Hi
    I am trying on emulator S60 2 edition but is gaves "Feature is not supported(-5)" can u help me

  8. #8
    Registered User
    Join Date
    Jul 2005
    Posts
    41

    Re: Playing AMR file is solved, Here is the solution.

    Now I use this solution for 3rd mr.
    It works on emulator and E50; but has some problems on E61.

    It can play amr on E61.
    But it gets KErrDied in MapcPlayComplete() after I pause and play several times.
    And it also gets KErrDied after I use CMdaAudioClipUtility::SetPosition() and play several times.
    When I made test, there is no call and I disable the key tone.
    I set the priority to EMdaPriorityMax.

    I made test on four E61 mobiles.
    I get E61 firmware version by pressing "*#0000#"

    1.E61 1.0610.04.04 OK
    2.E61 1.0610.04.04 OK
    3.E61 2.0618.06.05 fail
    4.E61 3.0633.09.04 fail

    Do this have some issues with E61's firmware version?

  9. #9
    Registered User
    Join Date
    Jul 2005
    Posts
    41

    Re: Playing AMR file is solved, Here is the solution.

    I solve the problem. It is related to ARM code.

Posting Permissions

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