Need clarification on using audio on button click,

2019-01-29 11:05发布

问题:

This is a WP 7.1/7.5/Mango Silverlight app.

I have a requirement where I need to play sounds on image click (3-4 images) and also an audio plays when user navigates to the page first time.

So I implemented that using MediaElement as mentioned here: Windows Phone 7.1 - Media Element not playing

Issue: Now I was testing the app. I started playing radio on the phone. Then started my app. Radio was still playing. Now when I navigated to the page that has audion on page Load, radio stopped.

Certification Requirements (6.5 - Non Music..) is very confusing: http://msdn.microsoft.com/en-us/library/hh184838(v=vs.92).aspx

Questions:

1: Do I need to ask user permission in this case (using a pop-up) before playing my audio?

2: Req 6.5.3 says no need to ask permission for non-interactive audio. What is that?

3: If I have to ask the user and if user selects No i.e. not to stop thier radio(or other music), then the only was for me to still allow to play my audio is using SoundEffect insted of MediaElement. So am I doing wrong with MediaElement?

4: I am also planning to add a background/ambience music to my app in future once I am done setting up above audios. Req 6.5.4. says - The SoundEffect class must not be used to play a continuous background music track in an application. No so in that case I am left with MedieElement only. Here's rhe Sound Sample(second one) I found: http://msdn.microsoft.com/en-us/library/ff431744(v=vs.92).aspx#BKMK_Media Is this the only way I can do?

Any suggestions really appreciate.

Note: The button click and page load audio files are short clips(max 5 secs) e.g. How are you?, What's your name? It's so much fun here, etc. So they are not songs.

回答1:

To answer one (or more) of you questions:

  1. You do not need to ask the user permission before playing audio
  2. All this means is if something is playing before your sound plays you must resume it
  3. No you should be using a sound effect if its a sound effect and a media element if its a media file. Sound effect are usually 5-10seconds and not continuous. BAckground music that loops is not a sound effect.
  4. In Silverlight for WP7 only one MediaPlay can be played at a time. I got around this by making my project a Windows Phone Silverlight an XNA application Refer to my previous post. The idea is that my XNA part plays the sound effects while my mediaelement plays the background audio.


回答2:

It can be a little confusing sometimes. Here is how I understand it:

You don't ask permission when all these conditions are met:

  • The sound doesn't repeat
  • The sound is interactive (in response to something the user did, like click a button)
  • You don't stop the background music (which means not using a MediaElement)

You do ask permission when:

  • The sound repeats or is continuous
  • The sound is like background music
  • You use a MediaElement (Because it stops the background music)

A clarification on interactive sounds: in my opinion a sound to signify that the program's state has changed (such as a timer's alarm going off) is still somewhat interactive and wouldn't need permission. Unless of course you start playing a song that functions more as background music.