WP7 play audio classes [closed]

2019-09-16 14:37发布

问题:

I read that Windows Phone 7 provides many classes for playing audio

MediaElement

SoundEffect

MediaPlayer

BackgroundAudioPlayer

What are the differences among them ? What should I choose

回答1:

MediaElement is a control that sits within the visual tree (which means you need to have it on your page somewhere, even if it's hidden, otherwies it won't play). You can stream songs from isolated storage, your XAP file, or on a network. The supported file types can be seen here.

SoundEffect is an XNA component and is, generally, used for things like looping background music or a gun shot. This is similar to MediaElement in the sense that it doesn't alter the user's MediaPlayer settings, but a difference between MediaElement and SoundEffect is that you can have multiple SoundEffects playing at the same time, whereas you can only have one MediaElement control on a page. Also, I believe only WAV files are supported. Even though it's an XNA component, it can be used in Silverlight.

MediaPlayer is the system-wide player. It's the one that's used when you play a track from the Music and Video Hub, and the one you control when you press the phone's volume button and see Universal Volume Control (the overlay the comes down with the the play, pause, next, and previous buttons). If the user is currently listening to a track and they run your app, which takes over MediaPlayer, the user's track will be stopped and replaced with your one.

BackgroundAudioPlayer is designed to let the user leave your app but continue playing your app's music. This is what the main music player does, which is why you can close the Music and Video hub, yet still continue playing music.

What you use depends on what your app is and what you need. There's no one-size fits all recommendation. Also, you should read the app guidelines to make sure your app isn't doing something with the audio that will fail marketplace submission.