Archive

Posts Tagged ‘Multimedia’

Fix: Enable Silverlight & other NPAPI plugins at Chrome web browser

Below I’m elaborating a bit more my related tweet:

 

Showing below the easiest of the suggested solutions that I found in this page

 

At Chrome’s address bar you type:

chrome://flags/#enable-npapi

and press the ENTER key on the keyboard

image

Then you should see a page Chrome generates to change some of its internal settings. When NPAPI is disabled the respective entry should appear in grey background like below.

image

Press Enable at the setting “Enable NPAPI Mac, Windows”

After enabling NPAPI the page should look like this (with the respective setting in white background):

image

After enabling the NPAPI option, close the Chrome webbrowser and reopen it.

 

You can then test if Silverlight is working by visiting for example

http://studio.clipflair.net (ClipFlair Studio Foreign language learning application) or http://zoomicon.com/amnesiaofwho (Amnesia of Who memory game)

 

Btw, Chrome also is available as a Windows 8 app, in which mode it probably doesn’t support plugins at all, so if you’re running it on Windows 8 and see it always full screen inside a scrolling container, use the Chrome menu from the top-right of its window and select the option there to switch to the desktop version of Chrome instead (should say "Relaunch Chrome in desktop mode")

HowTo: Hide Video area of Silverlight Media Framework Player

Since our onoing project ClipFlair is a follow-up of the succesful project LeViS, during its development I’m also looking at covering possible use-cases I infer from feedback entries at LvS application issue tracker on Codeplex (note that ClipFlair is also opensourced on Codeplex at http://ClipFlair.codeplex.com).

One such issue (http://lvs.codeplex.com/workitem/11511) was titled “Allow video hiding while controller is visible for audio only”, so since Silverlight Media Framework (SMF) is used for the media player in ClipFlair, I looked into how to tell it to hide the video area.

Well, it seems that to hide the video and hear just the audio in SMFPlayer one needs to set MediaPresenterElement‘s (a property of SMFPlayer class) MaxWidth and MaxHeight to 0. One can do that at an overriden OnApplyTemplate method in a class descding from SMFPlayer, or could also do it at a custom SMF player template.

Note that setting MediaPresenterElement’s Visibility property to Visibility.Collapsed makes the player not load the video at all, so that one was not an option.

One could define a VideoVisible DependencyProperty at a class descending from SMFPlayer:

    #region VideoVisible

    /// <summary>
    /// VideoVisible Dependency Property
    /// </summary>
    public static readonly DependencyProperty VideoVisibleProperty =
        DependencyProperty.Register("VideoVisible", typeof(bool), 
typeof(MediaPlayer), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.None, new PropertyChangedCallback(OnVideoVisibleChanged))); /// <summary> /// Gets or sets the VideoVisible property. /// </summary> public bool VideoVisible { get { return (bool)GetValue(VideoVisibleProperty); } set { SetValue(VideoVisibleProperty, value); } } /// <summary> /// Handles changes to the VideoVisible property. /// </summary> private static void OnVideoVisibleChanged(DependencyObject d,
DependencyPropertyChangedEventArgs e) { MediaPlayer target = (MediaPlayer)d; bool oldVideoVisible = (bool)e.OldValue; bool newVideoVisible = target.VideoVisible; target.OnVideoVisibleChanged(oldVideoVisible, newVideoVisible); } /// <summary> /// Provides derived classes an opportunity to handle changes to the
/// VideoVisible property.
/// </summary> protected virtual void OnVideoVisibleChanged(bool oldVideoVisible,
bool newVideoVisible) { MediaPresenterElement.MaxWidth = (newVideoVisible)?
double.PositiveInfinity : 0; MediaPresenterElement.MaxHeight = (newVideoVisible) ?
double.PositiveInfinity : 0; } #endregion

 

At first, to restore the MaxWidth/MaxHeight to show the video area again I tried to set them to double.NaN which didn’t work. Then I checked MaxWidth documentation which was saying:

The maximum width of the element, in device-independent units (1/96th inch per unit). The default value is PositiveInfinity. This value can be any value equal to or greater than 0.0. PositiveInfinity is also valid.

and

String representation of a Double value equal to or greater than 0.0. This is interpreted as a device-independent unit (1/96th inch) measurement. Strings need not explicitly include decimal points. For instance a value of 1 is acceptable.

The same Double range restrictions as mentioned in the Property Value section apply, except that you must use x:Static Markup Extension to set the value to be PositiveInfinity.

Per the 1st quote, one just needs to set MaxWidth or MaxHeight to double.PositiveInfinity (and not double.NaN that I originally expected) to reset it to its default value, that is behave as if a maximum width or height respectively has never been set.

As for the second quote, it basically says that XAML double fields need special treatment in order to specify a positive infinity value (if you ever need to, since you’d usually just skip the MaxWidth/MaxHeight field, unless you need to override some non-default inherited value). You would need to define a XAML namespace to point to the System namespace at mscorlib assembly (library), either at the root control in the XAML or directly where you need it:


<MyNameSpace:MyControl

      xmlns:sys="clr-namespace:System;assembly=mscorlib"

      MaxWidth=”{x:Static sys:Double.PositiveInfinity}”

      MaxHeight=”{x:Static sys:Double.PositiveInfinity}”

      …

/>

BTW, to hide the controller bar (called ControlStrip in SMF) you just set IsControlStripVisible property to false.

HowTo: load CaptionElements into Silverlight Media Framework player

Trying to make CaptionsGridWindow of ClipFlair serve captions editing on-the-fly to SMF (Silverlight Media Framework [now called MMPPF]) player component, I had a real hard time, plagued by a bug at TimedTextElementStyle. It seems to be setting default FontSize for captions using a “Cell” unit instead of using a “Pixel” unit. Currently SMF only supports “Pixel” units at FontSize of TimedTextElements according to the codedoc notes.

Another issue I had was that CaptionRegion constructor sets it to be active all the time (specifying a Begin value of a min possible TimeExtent and an End value of the max possible TimeExtent), so it renders ShowBackground.WhenActive setting useless for it. That is if you want the captions background to show up only when there are captions showing (active), then you have to set the CaptionRegion’s background to Colors.Transparent and set each CaptionElement’s background to some non-transparent color (note that both CaptionRegion and CaptionElement are TimedTextElements, with the later added to the former’s Children property, forming a TimedTree that is).

 

public void UpdateMarkers(MediaMarkerCollection<TimedTextElement> newMarkers)
 {
   if (newMarkers == null) return;

   CaptionRegion  region = new CaptionRegion();
   region.Style.ShowBackground = ShowBackground.WhenActive; 
//doesn't seem to work if other than transparent color is used region.Style.BackgroundColor = Colors.Transparent; foreach (CaptionElement marker in newMarkers) { region.Children.Add(marker); marker.CaptionElementType = TimedTextElementType.Text; marker.Style.ShowBackground = ShowBackground.WhenActive; marker.Style.BackgroundColor = Color.FromArgb(100, 0, 0, 0);
//use a semi-transparent background marker.Style.Color = Colors.White; //marker.Style.TextAlign = TextAlignment.Center; Length length = new Length { Unit = LengthUnit.Pixel, Value = 20 }; //must use this, since the default LengthUnit.Cell used
//at TimedTextStyle constructor is not supported
marker.Style.FontSize = length; } Captions.Add(region); }
%d bloggers like this: