Make correct URI for WP Game Library - c#

I am trying to create a library with sounds in it, but I cant get the URIs to work, if I use a online uri like
new Uri("http://www.archive.org/download/BrahmsViolinConcerto-Heifetz/03Iii.AllegroGiocosoMaNonTroppoVivace.mp3")
it works fine, so the issue is linking correctly to my folders in my project
My in my WP Game Librarys folder I have \Sounds\letters and in that folder is a sound named a.wma
My Method for loading this is
public void PlayLetter(string letter)
{
try
{
Initialize();
FrameworkDispatcher.Update();
var uri = new Uri(#"/Sounds/letters/" + letter + ".wma", UriKind.Relative);
var song = Song.FromUri("sound", uri);
MediaPlayer.Play(song);
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
}
And I of course give it string "a" as a parameter when it fails
I have also included the sound file in my project like
I just get a
A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.Xna.Framework.dll
But its an uri problem I am certain as I tried a online URI that worked just fine
Also I am in doubt of 2 things, is MediaPlayer the right thing to use in a game? And can a library play sounds (Or even contain them)

The typical thing in XNA would be to use a SoundEffectInstance:
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.audio.soundeffectinstance.aspx
Unfortunately SoundEffectInstance only works with wav files. If you want to play back longer music files - you can use a MediaElement - but that allows for playback of a single compressed audio file at a time only. Another option might be to play compressed from the MediaLibrary using the MediaPlayer class. You could also save your own compressed audio file in the MediaLibrary to play it from there. See:
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.media.medialibrary.songs.aspx

Related

Saving Bigger Files with TTS Android

Recently i used android TTS - I save the file as MP3 and play it using MediaPlayer so users can pause/resume etc.
It all works fine other than when i have a large text it just does not work.
I read that the android TTS has the limit of 4000 CHs? What should i do to tackle large amount of text?
The following is the code i am using to save MP3
Android.Speech.Tts.TextToSpeech textToSpeech;
...
textToSpeech = new Android.Speech.Tts.TextToSpeech(this, this, "com.google.android.tts");
...
textToSpeech.SynthesizeToFile(ReadableText, null, new Java.IO.File(System.IO.Path.Combine(documentsPath, ID + "_audio.mp3")), ID);
The following is the code i am using to playback the audio
MediaPlayer MP = new MediaPlayer();
...
MP.SetDataSource(System.IO.Path.Combine(documentsPath, ID + "_audio.mp3"));
MP.Prepare();
MP.Start();
It works for small amount of text but not for large text.
File gets saved (most likely just a corrupt file) because when i play it i get the following error
setDataSoruceFD failed: status=0x80000000
Java Solution is also acceptable
FYI - The question is about the max text size as I can generate the file for smaller text
Cheers
In Android ASOP (at least since API-18), TextToSpeech.MaxSpeechInputLength is set to 4000.
Note: OEMs could change this value in their OS image, so it would be wise to check the value and not make any assumptions.
Note: You are naming the output with an .mp3 extension, but by default the files created will be .wav formatted, some speech engines do support other formats/bitrate/etc. but you are passing null for the parameters.
Unless you want to deal with properly joining multiple wave files, I would recommend that you break your text into smaller parts and synthesize multiple files.
You can then play these back in sequence (using the MediaPlayer Completion event|listener).

ExpressionPlayer does not play Azure Smooth Streaming Source

I'm writing a VOD solution. For some time I have been working with the SSME:SmoothStreamingMediaElement successfully for testing and now I would like to utilise one of the Expression Players.
I'm using Azure Media Services, specifically Smooth Streaming. While these work fine in SSME I can't get them to work with an ExpressionPlayer. I don't know why.
I'm now at a point where I'm hard coding a Uri to try and get this to work as below:
void dataConectorPopulatePlaylistDownloadComplete(MemoryStream returnData, EventArgs e)
{
<snip>
var myPlaylist = new ExpressionMediaPlayer.Playlist();
var playlistItem = new PlaylistItem();
playlistItem.MediaSource = new Uri("http://xxxxxms1.origin.mediaservices.windows.net/b78750fc-9e2f-448c-86e3-d5de084791ea/GOPR0009.MP4-b2d2b578-3560-42c6-9927-2a791f395e19.ism/manifest",UriKind.Absolute);
playlistItem.IsAdaptiveStreaming = true;
myPlaylist.Items.Add(playlistItem);
SmoothPlayerStreaming.Playlist = myPlaylist;
<snip>
}
Using the above returns 404 not found in the player video playback window.
This is a valid URL and a valid Smooth Streaming Uri. Using this exact same Uri in a SSME control works fine.
What have I done wrong?
The ExpressionMediaPlayer class makes a hidden call to the ClientBin/SmoothStreaming.xap file. If you don't have it there - you should add it.
Here is the link to the blog post where you can download the xap file and source code of the expression player. Direct link
After you download the archive above, you can find this file at this path: EE4SP1SilverlightDefaultWithAudioVolume.zip\Templates\Silverlight Default -- with Audio Volume On Start\SmoothStreaming.xap
If it still doesn't work, you should replace the MediaPlayer.dll by projects from the archive. You need to add (Add -> Existing Project) 3 projects from the SharedV4SP1 folder: MediaPlayer, OfflineShared, PlugInMSSCtrl.
I've already tested your code in my application and it started to work after I have copied the xap file and replaced the dll-reference by existing projects.

Splicer Libraries are not supporting the mp3 format

I'm a trying to create a simple application in C#.NET that can generate a video file from a stream of Images and an audio file.
I chooses the Splicer and its working perfectly fine with my part of code. However when I try to put an mp3 audio format it shows an ERROR:An invalid media type was specified.
I scanned the Splicer forum but didn't get anything useful.
Any kind of help is appreciated.
Here is a simple code:
using (ITimeline timeline = new DefaultTimeline())
{
IGroup audioGroup = timeline.AddAudioGroup();
ITrack rootTrack = audioGroup.AddTrack();
rootTrack.AddAudio("testinput.mp3");
using (
WindowsMediaRenderer renderer =
new WindowsMediaRenderer(timeline, "output.avi", WindowsMediaProfiles.LowQualityAudio))
{
renderer.Render();
}
}

Getting MP4 File Duration with DirectShow

I need to get the duration of an mp4 file, preferably as a double in seconds. I was using DirectShow (see code below), but it keeps throwing a particularly unhelpful error. I'm wondering if someone has an easy solution to this. (Seriously, who knew that getting that information would be so difficult)
public static void getDuration(string moviePath)
{
FilgraphManager m_objFilterGraph = null;
m_objFilterGraph = new FilgraphManager();
m_objFilterGraph.RenderFile(moviePath);
IMediaPosition m_objMediaPosition = null;
m_objMediaPosition = m_objFilterGraph as IMediaPosition;
Console.WriteLine(m_objMediaPosition.Duration);
}
Whenever I run this code, I get the error: "Exception from HRESULT: 0x80040265"
I also tried using this: Getting length of video
but it doesn't work either because I don't think that it works on MP4 files.
Seriously, I feel like there has to be a much easier way to do this.
Note: I would prefer to avoid using exe's like ffmpeg and then parsing the output to get the information.
You are approaching the problem correctly. You need to build a good pipeline starting from source .MP4 file and up to video and audio renderers. Then IMediaPosition.Duration will get you what you want. Currently you are getting VFW_E_UNSUPPORTED_STREAM because you cannot build the pipeline.
Note that there is no good support for MPEG-4 in DirectShow in clean Windows, you need a third party parser installed to add missing blocks. This is the likely cause of your problem. There are good Free DirectShow Mpeg-4 Filters available to fill this gap.
The code sample under the link Getting length of video is basically valid too, however it uses deprecated component which in additional make additional assumptions onto the media file in question. Provided that there is support for .MP4 in the system, IMediaPosition.Duration is to give you what you look for.
You can use get_Duration() from IMediaPosition interface.
This return a double value with the video duration in seconds.
Double Lenght;
m_FilterGraph = new FilterGraph()
//Configure the FilterGraph()
m_mediaPosition = m_FilterGraph as IMediaPosition;
m_mediaPosition.get_Duration(out Length);
Using Windows Media Player Component also, we can get the duration of the video.
I hope that following code snippet may help you guys :
using WMPLib;
// ...
var player = new WindowsMediaPlayer();
var clip = player.newMedia(filePath);
Console.WriteLine(TimeSpan.FromSeconds(clip.duration));
and don't forget to add the reference of wmp.dll which will be
present in System32 folder.

How would I use a pack uri resource with media player?

I have some very simple code which just needs to play a sound with a specified volume, as follows :
var mp = new MediaPlayer();
mp.Open(uri);
mp.Volume = volume;
mp.Play();
The problem arises because this is part of a Prism module. I don't know where the executing assembly is going to be so I can't use a relative Uri or siteoforigin and MediaPlayer doesn't understand the pack Uri syntax.
I have a resource wav file at the root of my assembly called "notify.wav", but I have no way to pass it into MediaPlayer via a Uri and can't see any other way to load it.
How do I play the file?
Since the resource is embedded and the MediaPlayer doesn't support pack uri, you'll need to read the resource in as a stream and write it out to file.You should then be able to load the file into the player as necessary.
I would write the file to my applications directory so that once extracted from the assembly, you can just reference the file directly.
Hope this helps
First you should declare a variable that is string for your media folder's path. This variable holds the path. just like:
string url = #"C:\Users\Alico\Documents\visual studio 2010\Projects\WpfBrushesTest\WpfBrushesTest\Dido - Thank You.mp4";
and then
mp.Open(new Uri(url,UriKind.Relative));
I’m afraid Media player does not support pack URI.
Have you tried Directory.GetCurrentDirectory or Environment.CurrentDirectory?
Use ContentResolver class to retrieve the songs from the device and catch with Song.XML that include (TextViews for Title, Article, Album, etc). This XML is later embedded into the MainActivity XML(including ListView) using Adapter class and then you can call onClick(Song.XML) to play the songs (Setting URI ) on MainActivity XML, later you can set Seekber, Next, Previous and Play function.
If you want, I will give you full codes but I am trying to play a song from another Activity using a new UI design and class file, still searching.

Categories

Resources