As you have seen in the previous sections, MCOP is the basis of many multimedia things, and it allows you many freedoms. However, in the very common situation in which you just want to notify the user by playing a sample, there are simpler interfaces. Also, not all media types have been integrated so far; I'll try to briefly address the other possibilities that are available. There are two very simple ways to get a sound played in a KDE application. Of course, they use the aRts soundserver. However, they are available in the kdecore library and require no extra libraries. Thus, they are the most convenient forms of doing audio. First is the KAudioPlayer class (declared in kaudioplayer.h). It is supposed to play a sound file once, and without feedback. It works like this: You see, it's simple. It also has the capability to use signals and slots to play files. That looks like the following: However, for some applications, configurable sound events would be nicer for the user. For instance, how can you know which sound somebody prefers when getting new mail? How can you know whether the user prefers a sound at all, and not simply a message onscreen? Of course, every application could write the configuration for that itself. There is a better solution, however. Using the KNotify API, you create an eventsrc, where you describe your events. The user can reconfigure them later. The following is a sample eventsrc file (which needs to be installed in $KDEDIR/share/apps/keventtest/eventsrc): And here is how to use it: The user now can disable this event, specify another sound file, or make it a message box instead of a sound file in the KDE control center. This is why you should prefer events to simply playing files in most cases. | |
If you want to have background MIDI music for games and similar things, there is LibKMid. It comes with the capability to read and play MIDI files. It also does fork itself, so you don't have to care that it keeps running while you do longer calculations. I think that the following example will show the most essential things you need to know: The initialization and loading are done with one function call each. After you have triggered playing (kMidPlay), you can do anything you like (for instance, for a visual application, return into the event loop). LibKMid will care that the MIDI file keeps running in the background. | |
Finally , a hint about aKtion. Video isn't integrated in MCOP yet. It probably will be someday. However, that doesn't mean that there is no way to play videos. Based on the xanim decoders, aKtion is able to play most common video formats. It can, of course, be used as standalone application. However, it is also available as an embeddable part via the KParts technology. That makes it suitable for using it inside Konqueror, but also inside your application. | |
| |