Playing a video without opening another window or having the buttons - c#

I have a C# WinForms application, when you press a button at run-time, the application has to play a video but not in another new window, I want it to be in the form itself, also I don't have to see the Play/Pause/Stop etc. buttons of the Windows Media Player, just to have the video playing and when it ends return to the beginning where the button is situated. I couldn't find a question similar to this one, anyone has any ideas ? If any more information is needed just let me know.
Thanks alot!

Using Windows Media Player Control:
You can hide control buttons by setting uiMode property to none.
You can enable loop mode using settings.setMode method and setting loop to true
You can set a file path to play, by assign a path to URL property.
Since the settings.autoStart property is true by default, when you set the url, the player plays the media. Also you can use commands like Ctlcontrols.play or other control commands.
Sample Code
this.axWindowsMediaPlayer1.uiMode = "none";
this.axWindowsMediaPlayer1.settings.setMode("loop", true);
this.axWindowsMediaPlayer1.URL = #"d:\video1.wmv";
Resources
How to: Embed Windows Media Player on a Form
AxWindowsMediaPlayer Object Properties, Methods and Events

Related

WPF MediaElement doens't show video when LoadedBehavior="Manual"

When LoadedBehavior attribute of MediaElement, is set to "Manual",
I can see the video in the previewer, but when I run the application, the video is not displayed at all.
When LoadedBehavior is set to "Play", it works fine.
The 'Build Action' property of the video file is set to "Content".
The 'Copy to output' property of the video file is set to "Copy Always".
This is the code which doesn't display the Video:
<MediaElement Source="Videos\abc.mp4" Height="300" Width="300" LoadedBehavior="Manual"/>
So I expect the media player to be displayed with the right buttons, and let the user to chose when to play, pause, stop
Then your expectations are simply plain wrong because the MediaElement control doesn't come with any such buttons.
You'll need to add the buttons yourself and then hook up event handlers or commands to them where you call the Play, Pause and Stop methods.
The other option is to call the method(s) programmatically without the use of any buttons in the UI, but when you set the LoadedBehavior to Manual, you have to call Play() explicitly one way or the other for the media to play.
You have set the LoadedBehavior to "Manual" this means you need to start the MediaElement 'manual' (ha funny ;) ) Just call Play() in your code
Here is the doc

MediaElement possible memory leak on new media load?

I am developing WPF app for a media player in c# and I am using the mediaElement control to host media.
As I want the user to be able to load both video and images in the player, I ve made a simple if-then-else statement inside the mediaOpened event, to check every time that a new media is loaded, if it hasTimespan (and therefor the player sees it as a video) or else as a picture.
To check if this if/else statement was working, I placed a message box in each case to give me feedback that indeed the player recognizes correctly the media type.
So far so good.
I load a video, everything goes as expected and I get my message box saying "video!".
But when I load a 2nd video the message box appears 2 times.
When I load one more video, the message box appears 3 times!
Even weirder, if I load a picture next, the message box appears 4 times but instead of a sequence of message boxes like this,
"video!" "video!" "video!" "picture!", I get
"picture!" "picture!" "picture!" "picture!".
It seems that the player is storing the media (or the mediaOpened events) in some kind of a list and every time I load a new one, it checks all the media in that list and gives me a message for each one. (I haven't wrote any code to support a playlist feature yet, so I don't know where these media could be being stored...)
I ve tried stating the mediaElement's source as null when the user presses the load new media button, to make sure the mediaElement source is clean before the new media gets loaded, but it did not have any effect.
Does this sound like a memory leak?
Am I missing a specific unloading event that I should call upon media change?
Thank you!
So it turns out that in most online examples on how to develop a mediaplayer,
everybody suggests using this next line upon clicking the load button in the player:
mediaElement.MediaOpened += new RoutedEventHandler(mediaElement_MediaOpened);
but no one seems to be aware that these media need to be unloaded when you load a new one, which is possible by placing the exact opposite, before we set the new source of the media element, so it would be in this order for example:
mediaElement.MediaOpened -= new RoutedEventHandler(mediaElement_MediaOpened);
mediaElement.Source = new Uri(dlg.FileName);
mediaElement.MediaOpened += new RoutedEventHandler(mediaElement_MediaOpened);
Hope this helps somebody out there!

How to access PickerFlyout's app bar in a WP 8.1 XAML App

I'm writing a custom picker with the PickerFlyout class. By setting the ConfirmationButtonsVisible property to true, the flyout will show an application bar with an accept and a cancel button.
My problem is that the picker I am writing does not always have a valid value, and therefore I would like to disable the accept button when it does not make sense. Is there a way to do this in a Windows Phone 8.1 XAML app ("Store app")?
Other possible solutions:
An alternative solution would be to show my own app bar instead of the one given by ConfirmationButtonsVisible, which is possible by setting one in the Opening event. However, when this is done if the "overflow dots" of the application bar is clicked, the flyout will close. Apparently there is no way to prevent a flyout from closing.
If all else fails I will have to write a custom Popup, but I would rather not do this because the opening and closing animations used by PickerFlyout do not seem to be available as resources (internal to the class maybe?).
As long as there are items only in the PrimaryCommands section the flyout stays on screen when the overflow dots are tapped. Thus it is possible to temporarily replace the page's app bar with a new one for the duration of the flyout as long as no items in SecondaryCommands are needed. The accept button can be disabled in this new app bar.

Creating popup without possibility to tab to a background element

I am trying to create a popup but when it is open it is still possible to use the tab key to switch the focus to an element in the background (e.g. to a button and use space to press is). The only way I found until now is to check on every lostFocus event (which also fires for every element contained in the Border element) and check if the focus is now in a element inside the Border. If not I manually set the focus.
Is there a nicer way to keep the focus within the Border (or a Grid,...)
I'm working on a Windows 8 App.
Do you mean that using a Modal Dialog with Form.ShowDialog(Owner) still allows you to focus the parent components with Tab?
Can you give a sample of your code call?
Form2 form = new Form2(); //Make an instantiation of your Form
form.ShowDialog(); //ShowDialog()!!! NOT form.Show()!!! Or anything else :/
A few ideas:
Set Enabled to False on the background visual tree, though that might change the way things look if you still want to show them partly
Set IsHitTestVisible to False to disable pointer input
Use RenderTargetBitmap.Render() if targeting Windows 8.1 to render the content of the background to an image and simply replace all that visual tree with an image of it

Turn off default sound when displaying MessageBox in WP7

Is there a way to turn off the sound that the Messagebox plays when it is displayed in WP7?
There's no way to change this behaviour with the Silverlight MessageBox class. If, however, you use Guide.BeginShowMessageBox (from the XNA libraries) you can control whether sounds are played or not.
No, currently there is no way you can disable the sound that is triggered by the MessageBox class. That is a feature tied to the system and unless the device is on mute, the sound will be played.
With XNA's async version you can do this, though (as mentioned by Matt):
Guide.BeginShowMessageBox("Title", "Text", new List<string>() { "OK" }, 0, MessageBoxIcon.None, new AsyncCallback(YourCallback), null);
Here, MessageBoxIcon defines the sound and not the icon (which is nonexistent on Windows Phone for a MessageBox).
Note: you need yo add a reference to Microsoft.Xna.Framework.GamerServices.

Categories