How do I play a sound in WP8? - windows-phone-8

Sounds silly but Im having a heck of a time playing a .wav file in WP8. There does not seem to be a definitive, quick and easy guide on how to do this. i have the following code bit it crashes when I try to play the sound.
Any ideas? Thanks!
MediaElement mp1 = new MediaElement();
mp1.Source = new Uri("Assets/audio/myfile.wav");
mp1.Play();

Make sure that you have these references..
using System.Windows.Resources;
using Microsoft.Xna.Framework;
Now follow this step:
StreamResourceInfo _stream = Application.GetResourceStream(new Uri("/Assets/audio/myfile.wav", UriKind.Relative));
SoundEffect _soundeffect = SoundEffect.FromStream(_stream.Stream);
SoundEffectInstance soundInstance = _soundeffect.CreateInstance();
FrameworkDispatcher.Update();
soundInstance.Play();
Hope for success.

Related

setInterval with play() in flash as3?

I'm trying to play a sound (notification sound) in my flash application and I need to play the sound until the user clicks on something else to stop it.
I can play the sound properly but the issue is that it will only play once but i need it to play constantly (a short delay between each play maybe?).
my current code is this:
var mySound:Sound = new Sound();
mySound.load(new URLRequest("iphonenoti_cRjTITC7.mp3"));
mySound.play();
so I thought I can use setInterval(mySound,5000); in my code but this doesn't work which means it doesn't play the sound on the loop!
could someone please advise on this?
Thanks in advance.
Well, reading the Documentation of setInterval it states that the first parameter should be a function. In your code, you are passing an Object of the type Sound.
So, there are a couple of options, I'll show you the quickest and dirtiest one.
Instead of setInterval(mySound,5000); you write setInterval(mySound.play,5000);

Shoutcast aacplus streaming with As3

i want a flash player for shoutcast servers. if shoutcast's content type is mpeg, codes is working. But if shoutcast's content type is aacp, codes not working.
Codes;
var channel:SoundChannel;
var sound:Sound = new Sound();
sound.load(new URLRequest("http://yonradyo.radyolarburada.com:8020/;"));
channel = sound.play();
What should I do? Thanks.
The Project Thunder Snow (https://code.google.com/p/project-thunder-snow/) is not so fresh, but still working solution for playing aac/aacp streams on PC (but not on mobile platform).
The page https://code.google.com/p/project-thunder-snow/wiki/NBaccPlayer contains a code example simple enough.

Sound not being played

var sound:Sound = new Sound(new URLRequest("Phone.wav"))
sound.play(0, 20);
Why does sound not play? There are no errors.
Flash doesn't support loading external WAV files with the Sound class, only MP3s. I don't know why it isn't giving any errors but I haven't used the Sound class much myself so it might be normal.
There are three solutions for this. First of all, WAVs are supported if you import them into the library as Sound objects. This is probably the best choice if you're using the Flash IDE.
If you're not using the IDE, you may be able to embed the file instead using Flex's [Embed] tag, if you're compiling it using the Flex SDK.
Otherwise, can either convert your sound to an MP3 file and load it as usual:
var sound:Sound = new Sound(new URLRequest("Phone.mp3"));
sound.play(0, 20);
Or, if you prefer to use a WAV, you can use the as3wavsound library. Here's a tutorial outlining how to use it.
Hope that helps!
You need to use a SoundChannel try this.
var soundChann:SoundChannel;
var sound:Sound = new Sound(new URLRequest("Phone.wav"))
soundChann = sound.play();

Load Microsoft Document in Flash Actionscript3

I want to load microsoft word/excel document into swf. I have written the actionscript like following:-
var myloader:Loader = new Loader();
myloader.load(new URLRequest("test.doc"));
board.addChild(myloader);
Thanks in advance,
Prosenjit
But this code is not working. May I need to have a parser.
Can someone please help me out for this.
My github project may be able to help you out https://github.com/childoftv/as3-xlsx-reader

How do I include flashvars in AS3?

I am brand new to AS3 and I am trying to move all of the data from an html file, into a swf.
The old html file contained this coding:
<EMBED src="https://www.pandora.com:443/radio/tuner_9_2_0_0_pandora.swf" WIDTH="640" HEIGHT="528" FlashVars="_tunervar_shost=www.pandora.com">
So far from what I have learned I can use the loader, to substitute for the src. So in my swf, I have
var myLoader:Loader = new Loader();
addChild(myLoader);
var url:URLRequest = new URLRequest("https://www.pandora.com:443/radio/tuner_9_2_0_0_pandora.swf");
myLoader.load(url);
What I can't figure out though, is how to change the FlashVars from html into AS3. I have done a bit of research and from what it sounds like, I have to use something called root. I am completely lost on how to use this, and I am not even sure if this is the correct way to script it. Can someone help explain this to me?
One other problem I am having, is for some reason, the swf I am loading is blurry. Is there any way to fix this?
Try appending them to the asset that you're loading:
var url:URLRequest = new URLRequest("https://www.pandora.com:443/radio/tuner_9_2_0_0_pandora.swf?_tunervar_shost=www.pandora.com");