XNA MediaPlayer ContentLoadException was unhandled - c#

I want to use the MediaPlayer object to play one background song. Everything is fine until I try to start the program.
I have seen people using only two lines of code in order to play a song, this is what I do in the LoadContent method:
Song song = Content.Load<Song>("song");"song_title"
MediaPlayer.Play(song_title);
I get this in error
Microsoft.Xna.Framework.Content.ContentLoadException was unhandled
HResult=-2146233088
Message=Error loading "song". File contains Microsoft.Xna.Framework.Audio.SoundEffect but trying to load as Microsoft.Xna.Framework.Media.Song.

Related

how to get Android MediaPlayer to recognize audio/aacp correctly?

I have the following problem:
if I hand over an uri with the Content Type audio/aacp to the MediaPlayer for Android, the MediaPlayer won't recognize the content type as it should and throws an exception.
How can I change it so the MediaPlayer recognizes and uses this content type correctly?
Just as a side note i still have uris with different "Content Types" which it recognizes correctly. (and i obviously still need that working)
here is some of my code (i'm not sure if that is helpful or not):
readonly MediaPlayer player;
internal StreamingAudioPlayer(System.Uri uri)
{
player = new MediaPlayer();
player.Completion += OnPlaybackEnded;
player.SetDataSource(Android.App.Application.Context, Uri.Parse(uri.AbsoluteUri));
player.Prepare();
}
If you have any questions or need more information, just say so. I'm happy to provide what I can.
Edit: More information about the exception(s):
if I try to start the app with the uri, I get a Java.IO.IOException: 'Prepare failed.: status=0x1'
In the Output it also says:
[MediaPlayer] Couldn't open (and then the uri here): java.io.FileNotFoundException: No content provider: (uri here)
[System] ClassLoader referenced unknown path: /system/framework/tcmclient.jar
[NetworkSecurityConfig] No Network Security Config specified, using platform default
[MediaPlayer] error (1, -2147483648)
If I start the app by using another uri and then changing to this specifiy uri I get following System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.'
The output says this time:
[MediaPlayer] Couldn't open (and then the uri here): java.io.FileNotFoundException: No content provider: (uri here)
[MediaPlayer] error (1, -2147483648)
System.Reflection.TargetInvocationException: 'Exception has been thrown by the target of an invocation.'

Redefinition Error In Unity Shader file. What needs to be done? Appropriate syntax please

So I'm trying to add a gameObject that accesses Shaders; I'm using Unity 2021.1
The shaders are all custom method and whenever I try to compile the scene; An error pops saying:
Shader error in 'Hidden/Post FX/Screen Space Reflection': redefinition of '_CameraDepthTexture' at line 31 (on d3d11)
Here's the link to my shader file

In Xamarin.Android getting resource id "Android.Content.Res.Resources+NotFoundException:" error occur

I want to get id(int) for audio file from Asset folder but it give me error.
var File_Id = Resources.GetIdentifier("my_file.ogg","Assets", PackageName);
Above line of code execute in android Service
it give error,
Error Log:
03-13 14:03:50.047 W/ResourceType(13170): No package identifier when getting value for resource number 0x00000000
Unhandled Exception:
Android.Content.Res.Resources+NotFoundException: Resource ID #0x0
this file "my_file.ogg" is in "Asset" folder ,build action set to "AndroidAsset"
The asset can be read using the AssetsManager. Try below code snippet to read file from asset.
Android.Content.Res.AssetFileDescriptor afd = this.Assets.OpenFd("File name");
Updated Answer :
The following code snippet will help to play media file directly from the Asset folder.
Android.Content.Res.AssetFileDescriptor afd = this.Assets.OpenFd(fullPath);
if (afd != null )
{
player.SetDataSource (afd.FileDescriptor, afd.StartOffset, afd.Length);
player.Prepare ();
player.Start ();
}
In my case, I had a Xamarin Forms project. I had included a resource in the iOS project which the xaml page was referring to, but forgot to include it in the Android project.

Windows 8 - WriteTextAsync exception "Cannot evaluate expression because a native frame is on top of the call stack."

I want to use StorageFile, to implement Reading & Writing as seen here
http://msdn.microsoft.com/en-us/library/windows/apps/hh758325.aspx#writing_to_a_file
With
public async void Save()
{
StorageFolder storageFolder = KnownFolders.DocumentsLibrary;
StorageFile sampleFile = await storageFolder.CreateFileAsync(PlayerPrefs.GetString("WorldName") +"_"+filename);
await Windows.Storage.FileIO.WriteTextAsync(sampleFile, "Swift as a shadow");
}
But the "await" line gives the exception
+ $exception {Cannot evaluate expression because a native frame is on top of the call stack.} System.Exception {System.UnauthorizedAccessException}
I'm using Unity with Windows 8 Store if this makes any difference.
Anyone know what the problem is here?
Cannot evaluate expression because a native frame is on top of the call stack
That only tells us that the thread is executing unmanaged code, hence it cannot evaluate the expression.
The real error is the System.UnauthorizedAccessException.
So open your Package.appxmanifest, go to the Capabilities tab and check Document Library Access.
Just create test certificate and check "Sign the ClickOnce manifests" in Signing option in Solution properties with right click on solution name in solution explorer.

How can I access a resource image within XAML in a user control library?

I'm writing a library of WPF user controls and am having trouble with a resource image that I'm trying to access via some XAML. Just for fun, the image displays as expected at design time and only fails at run time.
I've tried setting the build action to "none", "content", "resource" and "embedded resource", but I keep getting the following cryptic exception:
'Provide value on
'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an
exception.' Line number '18' and line position '6'.
Looking at the inner exception, it seems to be a problem with the pack URI. When I try:
<ImageBrush x:Key="mybrush" ImageSource="pack://application:,,,/Resources/an image.png" />
I get:
Assembly.GetEntryAssembly() returns null.
OK, so this is probably because my library is now being called from within another assembly. But when I follow the recommendations and try:
<ImageBrush x:Key="mybrush" ImageSource="pack://application:,,,my_assembly;component;/Resources/an image.png" />
I get an inner exception of:
"The URI prefix is not recognized."
To add to the fun, I have another image resource which I have no problem accessing via actual C# code (i.e. not through XAML).
What am I doing wrong? Feel like it will be really simple, but am head-desking at the moment.
Change ImageSource to
ImageSource="pack://application:,,,/my_assembly;component/Resources/your_image.p‌​ng"

Categories