I'm making a simple 2d game using WPF where the game objects need to emit a sound when they hit the walls of the screen, but I can't find anything that lets me play a sound effect in Windows Phone 8.1.
In Windows Phone 8 I was using the SoundEffect class from XNA, but I don't think XNA is supported in 8.1 any longer. Is there any equivalent class I can use?
Use a <MediaElement> with MediaElement.AudioCategory set to ForegroundOnlyMedia
If you want more controlled sound playback, you'll need to use DirectX.
Related
I am going to develop simple 2D game in Unity for Universal Windows Platform (Windows 10) and I am confused with these multiple devices.
Windows 10 Mobile phone is absolutely different from large desktop so:
How to make menu gui and game user interface compatible with all devices?
Add a Canvas Scaler component to the Canvas. This will automatically resize the elements, to match the current resolution. You can even change it runtime to resize all the UI elements at once.
Set the scale mode to Scale with screen size.
I'm creating an app (Windows Runtime) that requires sound to run in the background (even when the phone is locked) so I set the BackgroundMediaPlayer's isLoopingEnabled property to true in the background task but when I play back the audio in the app there is about a 1 second gap between the audio finishing and starting again.
I've also tried setting the position property of the player to 0 on the MediaEnded event but that bared the same result.
Is there any way to achieve gapless looping using the BackgroundMediaPlayer in Windows Phone 8.1???
There's no workaround for this feature AFAIK but Gapless Audio support is coming with upcoming Windows 10.
Is there any way to use wpf 3D engine in windows phone application? I tried to add dlls to project but Icould not.
No, Windows Phone does not support the XAML-based 3D stuff that WPF supports. To create a 3D graphics phone app, you have to use Direct3D and C++.
In My case I want to play a sound file from a C# class file.
I refer the examples with create Media Element in the xaml page.
I want to play a sound every 5 minutes. This process is behind of my application. I don't have a design page for this.
If your sound is a WAV file, try this:
Stream stream = TitleContainer.OpenStream("sounds/bonk.wav");
SoundEffect effect = SoundEffect.FromStream(stream);
FrameworkDispatcher.Update();
effect.Play();
Update
Please, take into account that SoundEffect class lives in Microsoft.Xna.Framework.Audio namespace and is part of the XNA Framework Class Library, which is not supported on Windows Phone 8.1 Runtime apps (not Silverlight one). This means that if you are planning to upgrade/port your application to universal either for Windows Phone 8.1 (and upper) or Windows 8.1 (and upper), this answer will not work for you, unfortunately.
Simply declare your Media Element in code:
MediaElement element = new MediaElement();
We have an XNA game, that is meant to run on Windows Phone 8 as well as 7.1.
Everything in-game works on higher resolution phones like WXGA, but our game runs at 800x480 since that is the only supported size for WP7.
Is there a way to detect higher res phones for XNA and set the PreferredBackBufferWidth and PreferredBackbufferHeight appropriately?
Or is there basically not a way to do this with the available XNA support on Windows Phone 8?
XNA may not support this but it looks like MonoGame (open source port of XNA which works on WP8) will support the higher resolutions. See Nokia's topic on MonoGame and WP8 for a primer.
You need to port your game to DirectX for WP8 to support higher resolutions.