Silverlight 4 MediaElement play sound - silverlight

I converted a local sound file to a resource, which built this in my XAML:
<UserControl.Resources>
<my:Uri x:Key="SoundFiles">file:///c:/Audio/HebrewDemo/Shalom.wav</my:Uri>
</UserControl.Resources>
I did this by pasting a local disk mp3 filename into source, then clicked on the "dot" by source and chose "Extract Value to Resource".
When I run, it tells me that "Uri" is not valid, and sure enough, in the Intellisense, I see other elements that start with "uri" but not just URI by itself.
In the real world I want to specify a dynamic mp3 file name. For example, I might have a database of foreign language words used for flashcards, I want to play a sound file on a URL. But I thought I would try to walk before running...
Now I'm trying this:
mediaElement1.Source = new Uri(
"http://HebrewResources.com/SoundFiles/Shalom.mp3",
UriKind.Absolute);
mediaElement1.Play();
The status bar in the FireFox browser indicates some data being transferred from the website. However, I never hear any sound. Could it just be an encoding issue? If it is not encoded properly, would I get an error?
Also, can I put the Uri statement in the load or make it run in the background, so the user can read the screen, at the same time the sound file is downloading? In other words, when he clicks the button to hear the soundfile, ideally it would already be preloaded for him. In this language-learning app, the user will see a word in a foreign language, and try to pronounce it himself, then he will click the "Play" button to hear the sound to check his results.

The first code which points to the local file won't work in a normal Silverlight application because of Silverlights "sanboxed" security model. Running a normal Silverlight application in your browser, you can't access local resources like you can if you were running an installed winforms/WPF application. Have a look at this video tutorial http://www.silverlight.net/learn/videos/all/local-file-access/, if you want to learn more about accessing local files using Silverlight.
In regards to your second piece of code, it should work, so quite possibly it's an encoding issue, and no unfortunately you often don't get any errors for things like that.
I created a sample app and pointed it at your mp3 file and it' wouldn't work, however a quick search for sample mp3s, lead me to another freely available (first hit). Using the code/url below, it works ok.
myMediaelement.Source = new Uri("http://www.robtowns.com/music/blind_willie.mp3", UriKind.Absolute);
In regards to the loading, it will start downloading the file when it hits the code that sets the source of the mediaelement. So if you set the source for the media element in your constructor or in your loaded event, it will automatically start downloading in the background. Then you just call myMediaelement.Play(); on the button click event.
If you find using Firefox a bit limited, when it comes to determine what and when something like external files or webservices are being loaded. There's a great free tool called Fiddler (http://www.fiddlertool.com/fiddler/version.asp) which will let you monitor those things very easily.
Good luck :)

Related

Windows 10 / 8 start menu tile icon size for classic WPF desktop applications

I'm actually wondering how you can control the icon size (or generally: which icon to use?) for a 'classic' WPF application appearing in the Windows 10 start menu as a tile shortcut.
I only found very few posts like this one on SO, but the only answer one gets is that the corresponding mechanisms are only implemented for 'modern' Windows apps. This may be true in terms of live tiles and manifest-based definitions.
However, there has to be a way of triggering 'bigger' icons. Specific example: I have built an WPF application that, when pinned to the start menu, only shows up with a small icon in it. This is the case for all 'classic' applications - see attached image of a shortcut to the 'Orca.exe' db editor. I do believe in a way to achieve bigger icons because I noticed the Mozilla Thunderbird application (which is a 'classical' application) shows up with this one (custom background color and big icon size).
Is there anyone who understands how to achieve this and may share his knowledge? I already extracted the used icons from executables/shortcuts and compared them, but both only provide standard icon sizes up to 256px, no difference there.
Thanks!
This is actually pretty simple, but I remember having a hard time myself finding the documentation (or realizing that this is perfectly working for 'classic' applications):
Reference: MS docs - How to customize Start screen tiles for desktop apps
You can control the described behaviour and appearence of start menu tiles with a xml file called [Software].VisualElementsManifest.xml, where [Software] has to be replaced by the name of the .exe file (without extension), e.g. thunderbird.VisualElementsManifest.xml. As you already mentioned it, you can peek into the Thunderbird folder for a working example of it's content. Basically it looks like this:
<Application xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<VisualElements
ShowNameOnSquare150x150Logo='on'
Square150x150Logo='VisualElements\VisualElements_150.png'
ForegroundText="dark"
BackgroundColor="#FF0000"/>
</Application>
You can even provide additional options and assets for proper scaling, localization and accessibility by creating proper ressource files, documentation from MS has step by step instructions for this.
Note that the documentation warns about it's deprecated content. I don't know how long this work or if they are planning to completely remove this way of tile specification in the future, however it went perfectly fine on all version of W10 so far.
Note #2: If you're trying this out with an existing installation/shortcut, you have to refresh the modification timestamp of the corresponding shortcut and then unpin/pin the tile again, otherwise the shell won't notice the new definition file existance. Simplest way to do so in PS (run as admin when modifying shortcut in the system folder):
(ls "$env:ProgramData\Microsoft\Windows\Start Menu\Programs\[ShortcutName].lnk").lastwritetime = get-date
or from CMD within the destination folder:
copy /b [ShortcutName].lnk +,,

Playing a .mp4 file while writing it

This is a very simple task that I had such a hard time trying to do. My goal is pretty simple: send an mp4 file from my server to my client, and while its buffering and downloading I want to already play it. That means that I need to play a video.mp4 file while writing it, and I need it to display on some platform that I can control - like wxPython or WPF-Ironpython. Naturally, no such platform will let me play an open file for writing.
I have tried to implement and HTTP server (although totally unnecessary for my case, as I am writing an application-based Server-Client app) that would accept Range request, and when I run the server and load the URL on Chrome, it all works perfect and I can seek and buffering is great, but when I load it from WPF MediaElement it fails to play the video for some point (I cant really tell why as there is no documentation for this, any API, tutorials etc). I am really desperate.
I even thought about playing a video from a buffer and then just changing the buffer's content, but it doesn't seem like this possibility exists.
I am really stuck at this and I would love to get some suggestions. Please note that I am not a professional in this so I would appreciate if you could explain this to me in simple terms.
Thanks!
Not possible. MP4 is not the correct container for your application. You must use something like HLS/dash/fragmented MP4.

Start a browser, any modern browser, from win 7 command line at a preset geometry. Is it possible

I am in need of writing a batch script, which will start "A" browser session at a certain location on the screen and at a certain size and display a locally stored and very simple HTML file. I am not picky about browser type. The html document is nothing fancy, no dynamic content. Just a scrolling marquee when there exists a file.
Is it possible to open any one of major browsers, that is available on win 7 platform, at a location (x,y coordinates in pixels) and at a certain size ? This will be used by an elderly person, who can close any open window by clicking the X sign on the right top corner but other thna that, quite computer illiterate and the screen used always occupied by other content with a bit of space available near the bottom, to scroll this message.
If it si possible, could you please tell me the syntax of the command to run in the batch file ?
This won't be possible in batch (the only options with the start command are Minimised/Maximised).
This will probably be possible in C# though. Even better, if you dont want the browser to be fancy like you said, you could easily make a browser in C#, and make it take a number of parameters which would adjust sign and postition. If all you need is for the user to observe a html document and then close the browser I would seriously recommend you learn some basic C# and make this, or post another question presenting you're conundrum tagged C#.
Mona
You can place your html content into an .hta file that will be handled by mshta.exe. This is a container for the web browser control, but running with the security of a desktop application. So, you can include the required code (javascript, vbscript or any other active scripting engine available on the machine) to access the window object and move / resize it as needed.

Silverlight 5 web cam capture: Two capture sources on the same device

I tried to attach the same Video Source Device (the WEB CAM) to two different CaptureSource objects but it looks like that want work.
The system throws an exception: A device attached to the system is not functioning. (Exception from HRESULT: 0x8007001F)
I think the web cam is locked on first CaptureSource.
Does anybody has an idea how to display two images from the same Device but from different capture source? I wanted to use a simple CaptureSource on one side and MediaStremSource with some filtering on the other side to see differences between original and filtered video source.
I wanted to use the plain CaptureSource because it's performance is better than MediaStreamSource. MediaStreamSource loses time when raises OnSample Event which is not happening with CaptureSource.
I know this exception, When you work on debug mode silverlight fails.
Run project by Ctrl+F5. (Release mode)
In addition use ask for permission methods this will display permission window for camera.
It is very capable, just did it myself. However, in experimenting with different cameras and different inputs.... 2 MS LifeCams connected to USB3 = same error. Connecting to USB2 hub to USB2 MB works like a charm. Also, if I run something like ActiveCam and it crashes, may need a reboot. Oh, you will need to use 2 capture sources.... but can still ask permission once.
Also remember not to use DefaultCaptureDevice but:
var dev1 = CaptureDeviceConfiguration.GetAvailableVideoCaptureDevices()[0];
var dev2 = CaptureDeviceConfiguration.GetAvailableVideoCaptureDevices()[1];
With perhaps better naming conventions and logic to check if devices exist etc...

WP7 MediaElement download problems

I'm running into problems on the WP7 with MediaElement downloading a 128kbps mp3 stream from a web service for a music player app that i'm working on. The file downloads correctly when the wp7 is on a wifi connection, but downloading sometimes stops when off of wifi. The problem is that i'm not getting any errors or exceptions when the downloading fails and the MediaElement state is "playing". MediaElement runs right past the downloaded portion of the stream and acts like it is playing, but there is nothing to play since the download stopped. I can somewhat replicate this issue based upon my location and using the 3g instead of wifi, so i believe it is due to a low connection. I don't believe any code needs to be shown in this instance, but i try to post something. I want to know if I have any control over this? Are there any other events I could use to detect when the download has failed? Is there another way I could download a mp3 stream that is more reliable and play it? Is there another player/component I should try?
Thanks in advance
You could always use MediaStreamSource to try to handle the download and implement streaming, to some extent. It is a more "painful" way of doing this since you will have to work with an extra media layer, but it pays off by improving playback stability.
Here is a starter example by Tim Heuer. Take a look specifically at how he takes advantage of a custom implementation of MediaStreamSource. Here is a more complex sample.
If streaming is not a requirement, you could download the file (and store it in the Isolated Storage) and then play from there.

Resources