quick_recipes (779892), страница 43
Текст из файла (страница 43)
Toresume the audio playback, simply call CMdaAudioPlayerUtility::Play().Performing rewind and fast forward is done by calling CMdaAudioPlayer::SetPosition(). It requires a parameter in the type ofTTimeIntervalMicroSeconds, which is the interval of the newposition in microseconds from the start of the clip (not from the currentposition).The following example shows how to rewind the current audio playback by one second:242SYMBIAN C++ RECIPESconst TInt KOneSecond = 1000000; // 1 second in microsecondsvoid CSimpleAudioPlayer::Rewind(TInt aIntervalInSeconds){iPlayerUtility->Pause();// Get the current position of the playback.TTimeIntervalMicroSeconds position;iPlayerUtility->GetPosition(position);// Subtract the interval from the current positionposition = position.Int64() –(aIntervalInSeconds*KOneSecond);// Set the new position.iPlayerUtility->SetPosition(position);iPlayerUtility->Play();}What may go wrong when you do this: When you call SetPosition(), CMdaAudioPlayerUtility does not move the position immediately.
It will continue playing for a couple of seconds untilits internal buffer is empty. Sometimes, you may notice that the playback continues for a while before it moves to the new position. In orderto have immediate rewind/fast forward effect, you must call Pause()before setting the new position, and then call Play() after that.4.7.1.3Play an Audio ToneAmount of time required: 15 minutesLocation of example code: \Multimedia\AudioToneRequired libraries: mediaclientaudio.libRequired header file(s): MdaAudioTonePlayer.hRequired platform security capability(s): NoneProblem: You want to play an audio tone, such as a beep sound, or asound from a certain frequency.Solution: The CMdaAudioToneUtility class is used to play an audiotone.
It uses an observer class, which implements MMdaAudioToneObserver. This observer will receive events and error notifications, forexample when it has been configured, when the tone has been playedcompletely, or when an error occurs.The following steps explain how to play an audio clip using CMdaAudioToneUtility:• Create an observer class, which implements MMdaAudioToneObserver. In the sample code, we use class CAudioTonePlayer.MULTIMEDIA243• Create an instance of CMdaAudioToneUtility and pass it a reference to the observer class.• Open the audio clip by calling one of the variants of the PrepareToPlay() method (CMdaAudioToneUtility::PrepareToPlayXyz()).
See the Discussion section for further details.• Wait until MMdaAudioToneObserver::MatoPrepareComplete() is called.• Within the callback, call CMdaAudioToneUtility::Play() tostart audio tone playback.• When the audio has been played completely, or if an error occurs,MMdaAudioToneObserver::MatoPlayComplete() will becalled.Discussion: There are several variants of the CMdaAudioToneUtility::PrepareToPlayXyz() methods, for instance:• PrepareToPlayTone() – used to play a single tone.• PrepareToPlayDualTone() – used to play a dual tone, which isa combination of two frequencies.• PrepareToPlayDTMFString() – used to play dual-tone multi frequency (DTMF) tones. These are used in the telephony signallingsystem.Tip: You cannot use PrepareToPlayDTMFString() to play DTMFtones to the telephony uplink.
It only plays DTMF on the local speaker.Please check the Symbian Developer Library documentation to see thecomplete list of methods supplied by CMdaAudioToneUtility.4.7.1.4Play a MIDI FileAmount of time required: 15 minutesLocation of example code: \Multimedia\MidiPlayingRequired libraries: midiclient.libRequired header file(s): midiclientutility.hRequired platform security capability(s): NoneProblem: You want to play a MIDI file on the device.Solution: The client API to play a MIDI file is CMidiClientUtilityclass. Like the audio player utility, the MIDI client utility class requires an244SYMBIAN C++ RECIPESobserver, which must implement the MMidiClientUtilityObserverinterface.The following steps explain how to play a MIDI file using CMidiClientUtility:• Create an observer class, which implements MMidiClientUtilityObserver.• Create an instance of CMidiClientUtility and pass it a referenceto the observer class.• Open the audio clip by calling CMidiClientUtility::OpenFile().• Wait until MMidiClientUtilityObserver::MmcuoStateChanged() is called.
The aNewState parameter has the valueEOpen if the file has been opened successfully.• Call CMidiClientUtility::Play() from within the observer tostart MIDI playback.• When the audio has been played completely, wait until MMidiClientUtilityObserver::MmcuoStateChanged() is calledagain. The aOldState parameter will be set to EPlaying andthe aNewState parameter will be set to EOpen.In our recipe, the CMidiPlayer class implements MMidiClientUtilityObserver and is used to play a MIDI file, \data\sample.mid, which is located at the same drive as the application.
For example,if the sample application is installed on the C: drive, then the file locationis c:\data\sample.mid.Tip: The Windows emulator does not support MIDI playback. You canonly test this example on the device.4.7.2 Intermediate Recipes4.7.2.1Get the Default Multimedia Storage LocationAmount of time required: 25 minutesLocation of example code: \Multimedia\AudioRecording and\Multimedia\CameraImageHeader files: pathinfo.h (S60), QikMediaFileFolderUtils.h(UIQ)Required libraries: platformenv.lib (S60), qikutils.lib (UIQ)Required platform security capability(s): NoneMULTIMEDIA245Problem: You need to retrieve the default path for storing multimediafiles.S60 and UIQ store multimedia files in different default folder locations.For example, the default path for audio files on S60 on the C: drive isc:\data\sounds, while on UIQ it is c:\Media files\Music.The location used to store files on the emulator may also be differentfrom that used on smartphone hardware.
For example, the UIQ’s emulatoruses c:\Media files\audio for audio files, compared to c:\Mediafiles\Music when storing files on the device.And that’s not all! Even when just considering phone hardware, thelocation in which files are stored in the phone memory may be differentto that used on the memory card. For example, in S60 the default videolocation in phone memory is c:\data\videos, while on the memorycard it is e:\videos.How can we write a code that is able to return the media pathindependent from the platform and media type?Solution: Unfortunately, there is no single solution to this problem.
S60and UIQ use different ways of getting media paths. You need to createtwo different implementations for each platform.Discussion:S60The class to handle various media paths on S60 is PathInfo. It isdeclared in the pathinfo.h header file, and the library to link againstis platformenv.lib.Some of the methods related to media path information are as follows:• PathInfo::PhoneMemoryPath(),• PathInfo::MemoryCardPath(),• PathInfo::VideosPath(),• PathInfo::ImagesPath(),• PathInfo::SoundsPath().The PhoneMemoryPath() method returns the root path in the phonememory, for example ‘c:\data\’.
The MemoryCardPath() methodreturns the root path on the memory card, for example ‘e:\’. Note thatthere is a backslash character at the end of the returned path.The other methods return the path of multimedia files. For example,VideosPath() returns ‘Videos\’. Again, there is a backslash characterat the end of the returned path.The following code shows how to get an absolute path of the audiofolder including the drive letter:246SYMBIAN C++ RECIPESvoid CAudioRecordingAppUi::GetAudioPathL(TChar aDriveLetter,TDes& aPath){aPath.Zero();if ((aDriveLetter == 'c') | | (aDriveLetter == 'C')){aPath.Append(PathInfo::PhoneMemoryRootPath());}else if ((aDriveLetter == 'e') | | (aDriveLetter == 'E')){aPath.Append(PathInfo::MemoryCardRootPath());}aPath.Append(PathInfo::SoundsPath());}The following example shows how to call the method above:TFileName audioPath;GetAudioPathL('c', audioPath);The audioPath will have the value of ‘c:\data\sounds\’ afterGetAudioPathL() is called.Similarly, if you call it using the statement:GetAudioPathL('e', audioPath);the audio path will have the value of ‘e:\sounds’.UIQNow, let’s take a look at UIQ.
The class to handle various media paths isCQikMediaFileFolderUtils. It is declared in the QikMediaFileFolderUtils.h header file. The library name is qikutils.lib.The methods used to retrieve paths related to multimedia files areGetDefaultPathForMimeType() and GetDefaultPathForMimeTypeL().The only difference between them is that the latter method can leave.The methods require three parameters. The first parameter, aMimeType,is the MIME type to convert to a folder path.
It uses only the first part ofMIME type. For example, if the MIME type is ‘audio/wav’, only ‘audio’will be used for matching.The second parameter, aDriveLetter, is the drive to query forthe default location. The final parameter, aFolderPath, is a referenceparameter which receives the absolute path of the media files excludingdrive letter. For example, it returns ‘:\Media files\audio\’ for audiofiles.MULTIMEDIA247Tip: You can also retrieve the root path of the media folder (i.e.,‘:\Media files\’) using the CQikMediaFileFolderUtils::GetMediaFilesRootL() method.The following code shows how to get the audio path in UIQ:void CAudioRecordingAppUi::GetAudioPathL(TChar aDriveLetter,TDes& aPath){CQikMediaFileFolderUtils* mediaUtils =CQikMediaFileFolderUtils::NewL(*iEikonEnv);CleanupStack::PushL(mediaUtils);// Get the path for imageTFileName mediaPath; // To receive the pathmediaUtils->GetDefaultPathForMimeTypeL(KAudioMimeType,aDriveLetter, mediaPath);// Construct a full path that contains drive letter.aPath.Zero();aPath.Append(aDriveLetter);aPath.Append(mediaPath);CleanupStack::PopAndDestroy(mediaUtils);}The following example shows how to call the method above:_LIT(KAudioMimeType, "audio/wav");TFileName audioPath;GetAudioPathL('c', audioPath);The audioPath will have the value of ‘c:\Media files\music\’on the UIQ device and ‘c:\Media files\audio\’ on the emulator.Similarly, if you call it using the statement below,GetAudioPathL('d', audioPath);the audio path will have the value of ‘d:\music\’ on the UIQ deviceand ‘d:\Media files\audio\’ on the emulator.4.7.2.2Play a Video ClipAmount of time required: 30 minutesLocation of example code: \Multimedia\VideoPlayingRequired libraries: mediaclientvideo.libRequired header file(s): VideoPlayer.hRequired platform security capability(s): None248SYMBIAN C++ RECIPESProblem: You want to play a video clip from a file, such as a 3GP or MP4file.Solution: The MMF class that is used to play video is CVideoPlayerUtility, which requires you to pass an implementation ofthe MVideoPlayerUtilityObserver observer class.Using CVideoPlayerUtility is similar to CMdaAudioPlayerUtility, except there is an additional step; that is, preparing thevideo clip to be played.