This is driving me bonkers! When trying to play a sound or any media element in a windows phone 8 app I get "Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED))"
And that is all it says. If I look at the stack trace it shows: at Windows.UI.Xaml.Controls.MediaElement.Play()
Example code is:
XAML:
MediaElement x:Name="sndClick" Source="Assets/Sounds/Click.wav" Volume="10" AutoPlay="False"
Code:
sndClick.play();
I am trying to port a Windows 8 app to Windows Phone 8. The Windows 8 app works perfectly with the exact same code. This must be some issue with the Windows Phone. Everything else works, it just crashes when the phone trys to play media.
Not all the elements that play sounds crash the program, unless you click them a few times. Some elements always crash on the first click. No sounds ever play, even if the program doesn't crash with the exception it never plays any sounds.
ONE time (and only one time) it played the first couple frames of one of the animation files (.wmv) and then crashed.
It is a weird problem. All the code is copied from the working Windows 8 program and everything works except for the media. If I comment out the sound.play()'s and I disable the media player the program works fine.
At first I thought it might be that the resources weren't copying so I set the "Copy to Output Directory" to "Always Copy". No effect.
I tried the simulators and I tried it on physical hardware, it is the same on everything.
It isn't a resource issue, the simulators and the hardware have more than enough system resources, the whole app is only 22mb's.
It's not a codec issue, the animation is a .wmv file and the sounds are all .wav. Both should be natively supported on any windows device.
I have searched around and seen others with similar problems but I haven't seen any solutions. Does anybody know what is causing this issue and how to fix it? I would very much appreciate it.
I am pulling my hair out on this.
Thanks,
-RW
OK I fix it.
Windows Phone 8.1 simply hates it when there is more than one MediaElement in the program... Even just playing one at a time throws the error and wont play any sounds.
It is annoying. It is further annoying that it doesn't seem that XNA works in 8.1 (at least I couldn't get it to work)
The solution was to use SharpDX.
Special Thanks to this post: Multiple audio stream in Universal App(Runtime API), XNA SoundEffect replacement
I removed all but one MediaElement and added installed SharpDX and SharpDX Xaudio2 from the package installer thing. Then:
using SharpDX;
using SharpDX.XAudio2;
using SharpDX.IO;
using SharpDX.Multimedia;
private void PlaySound(string strPath)
{
XAudio2 xAudio = new XAudio2();
var masteringVoice = new MasteringVoice(xAudio);
var nativeFileStream = new NativeFileStream(strPath, NativeFileMode.Open, NativeFileAccess.Read, NativeFileShare.Read);
SoundStream stream = new SoundStream(nativeFileStream);
var waveFormat = stream.Format;
AudioBuffer buffer = new AudioBuffer
{
Stream = stream.ToDataStream(),
AudioBytes = (int)stream.Length,
Flags = BufferFlags.EndOfStream
};
var sourceVoice = new SourceVoice(xAudio, waveFormat, true);
sourceVoice.SubmitSourceBuffer(buffer, stream.DecodedPacketsInfo);
sourceVoice.Start();
}
And then just:
PlaySound("Assets/Sounds/Click.wav");
It works quite well! And the one remaining MediaElement that I need for an animation works now. My hair is even starting to grow back (though it is growing back grey).
If anyone else is having this issue, this is the fix. I hope it helps someone.
Related
I wanted to revisit this question from before I first asked it. I'm developing a completely new version of my application and I cannot find any media player available cross-platform from the shared code in Xamarin.Forms so I'm stuck with using MediaElement as its the only one that provides the functionality of using embedded resources for video files. Unlike the other players out there all use API and URI to play videos from the internet which is not what I need.
After numerous testing on 2 different platforms, this app is for Android and iOS, I now can tell confidently that the flickering is only happening on Android devices and not iOS -> iPhones or iPads.
I wonder if there is any solution to pre-load the source file to the MediaPlayer which is what is under the hood for Android using MediaElement.
There are a few solutions that I've come up with but am not happy with.
1: Have an identical first frame image of the video and overlay it over the screen for 200 - 400 milliseconds and make it disappear. The problem with that is it is not easily scalable which I require as my app requires a large number of videos and getting the first frame of approx 120+ videos and having them all as assets are just not necessary.
2: Take a screenshot of the previous screen and display it over the video screen and make it disappear after 200 - 400 milliseconds and then make it disappear. The problem with this actual user experience becomes weird because you constantly see the previous screen and you see it just disappear even tho you've just come to a new page and you can definitely tell that you've moved pages.
In conclusion, I don't really know if this is a problem possible to solve by a user of the package or if requires someone who is in depth of understanding the package to fix this. This could also be a problem in Android side which doesn't load videos efficiently and this is causing problems in loading videos for Android platform apps
Many Thanks in Advance.
I'm trying to do some basic app, with System.Speech.Synthesis in c#
It's just a basic form with a text input and after pressing enter it reads the text using ss.SpeakAsync();
The goal is to play that sound on a exact audio output device on Windows but I can't achieve that.
I've tried do it by windows settings, App volume and device preferences, but it doesn't work, not sure why.
I'm setting the correct device, but it plays on the "default" anyways, no matter what I do. It works with any other application correctly (like browser for example) bit with mine it doesn't. It works when I change all system audio to that device, but the main goal is that i want only this app to use "cable input".
I've tried to use some 3rd party software to do this (https://github.com/a-sync/audio-router) but it doesn't work either. I set everything, and when I click "play" in my app, then my app crashes with an exception: „[17132] TrayReader.exe” exited with code -1073741819 (0xc0000005) 'Access violation'.
So maybe I'm able to set in the code the correct audio output device? Or how do I fix those previous errors? maybe I need to add some privileges or something? I'm mainly web developer, this is my first time with windows app.
//edit -> it works, when i change all my system audio to cable input, play some sound, and then go back to my main device. It seems like a windows bug?
you may use a 3rd lib Naudio; the example below shows how to return to current position in case the player was playing a song. The key code is player.DeviceNumber = deviceNum; in which deviceNum is 0, 1, 2... depending how many speakers are available in your PC.
A disadvantage of Naudio is that it loads completely the song before playing, and quite slow.
var playback = player.PlaybackState;
if (playback == PlaybackState.Stopped) // change and exit
{
player.DeviceNumber = deviceNum;
return;
}
var currentTime = reader.CurrentTime;
player.Stop(); // must stop to change output
player.DeviceNumber = deviceNum;
player.Init(reader);
reader.CurrentTime = currentTime;
if (playback == PlaybackState.Playing)
player.Play();
I'm dealing with a strange issue that's been giving me headaches for a long time.
I've got a Windows Phone 8.1 (WinRT) app, whose first version I published a couple of years ago. Over the last few months, I've been working on a major update which includes augmented reality as the most prominent feature.
Obviously, the app needs to make use of the camera preview, and that's where trouble starts. I've read discussions in other threads about problems with the camera API, but I didn't find a definite solution.
Before submitting the update, I performed extensive tests on my Lumia 620 and all worked fine. But if the app is downloaded from the store, it crashes and the camera picture goes green as soon as the camera preview starts. It is the very same app package and all required capabilites have been declared.
So basically I can't tell if my app works or not, unless I submit it to the store.
Any help will be appreciated.
Edit: After several hidden-app submissions, I've narrowed down the cause of the crash to the following block of code:
RandomAccessStreamReference rasr = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/Square44x44Logo.scale-100.png"));
var streamWithContent = await rasr.OpenReadAsync();
The last of the above lines causes the app to terminate. The same code works fine when the app is deployed from VS.
Any ideas?
It looks like the problem is now resolved. The cause of the crashes was the asset file. This file is a scaled version of the app tile, which is created automatically by Visual Studio. Using this file is allowed when the app is deployed from VS, but not in the store.
my first question here...
I have been searching how solve this issue i start a app using monotouch creating my MPMoviePlayerController like this:
this.mp = new MPMoviePlayerController(new NSURL("http://stream3.dyndns.org:1935/iphone/xeco.stream/playlist.m3u8"));
this.mp.useApplicationAudioSession=false //also try with true
this.mp.PrepareToPlay();
this.mp.Play();
Everything works great, i hear the audio
Notes:
I already search how fix this and on my plist file add UIBackgroundModes and string audio as many members advice. (Using the plist editor provided in monotouch). Also add this code to set the category of my audio session:
AudioSession.Initialize();
AudioSession.Interrupted += delegate{
Console.Writeline("interrupted");
}
AudioSession.Category = AudioSessionCategory.MediaPlayback; //also try ambientsound and others
The problem is:
How can i keep the audio playing when the app goes background, when the device blocks or the home button is pushed?
The stream always seems get muted when press home or block the device, when i return to the app the audio starts very quickly wich make me think that the app is streaming all the time but only doesnt hear.
I am testing only on the Iphone Simulator, i am starting to think that maybe this is caused only on simulator. any advice?
thanks in advance.
UPDATE:
I receive my licenses of monotouch and my register on the iOS Dev Program, so i test my app on the device. It works, the important part is on the AudioSession part:
AudioSessionCategory.MediaPlayback;
and when use the player on:
this.mp.useApplicationAudioSession=false
I receive my licenses of monotouch and my register on the iOS Dev Program, so i test my app on the device. It works, the important part is on the AudioSession part:
AudioSessionCategory.MediaPlayback;
and when use the player on:
this.mp.useApplicationAudioSession=false
The app works great on the device. Monotouch rules!
Been trying this for a while now.
All solutions I've seen on the net don't seem to work, specially the really simple way to do it.
WMPLib.WindowsMediaPlayer c = new WMPLib.WindowsMediaPlayer();
IWMPMedia i = (IWMPMedia)c.currentMedia;
c.currentMedia is always null.
It seems that new WMPLib.WindowsMediaPlayer(); is always creating a new instance of the Windows Media Player.
First I thought it was the fact that I was running visual studio as Administrator, but changing that did not help.
Seems I somehow have to connect to the running instance of wmplayer.exe but have unable to find a way to do that.
Btw. What I need is a full file url for the current playing song (or fullurl if streaming, but that's the least of my concerns now.)
Your question answered here.
A pretty straight way:
Get a WMP9 plugin here that will put your current song name on the
titlebar of the WMP window, and use
FindWindow P/Invoke to get the window
and get the song name. It shoud work,
though a little tricky.
Check here for more details.
Windows Media Player 9 Series Blogging Plug-in
A much more complex way:
Since your application and the WMP will be different processes, your
scenario requires some kind of
inter-process-communication (IPC). And
.NET offers Remoting for this purpose.
Below are some useful information:
How to interact with Windows Media Player in C#
Windows Media Player Remoting in C#
from SamAgain