Reputation: 540
I want to get URI of default.mp3
from resources
and play that file in System.Windows.Media.MediaPlayer
I included the mp3 file in resources folder as Content
and copy always
but I dont know how to play get the URI. I am currently doing this but its not working
uri = new Uri("pack://application:,,,/Resources/default1.mp3"); // This is not working neither showing and error
var player = new MediaPlayer();
//MessageBox.Show(uri.ToString());
player.Open(uri);
player.Play();
Upvotes: 1
Views: 4994
Reputation: 31
You can not apply file from resource to MediaPlayer in .Net. The music file should be placed in separatly file and Uri created with phisical file path.
Please, see the message details in MediaPlayer.MediaError event.
Upvotes: 1
Reputation: 157098
You have to set the 'Build Action' to 'Resource' in order to make the resource accessible through WPF.
You can change this in the properties pane of the file:
I got it working with these steps:
Resources\default.mp3
;Use this code:
Uri uri = new Uri("pack://application:,,,/WpfApplication1;component/Resources/default.mp3");
Upvotes: 0