1

I am trying develop a silverlight player based on SmoothStreamingMediaElement. For Ref: SSME:SmoothStreamingMediaElement Grid.Row="2" x:Name="medSmooth" AutoPlay="True" MinWidth="320" MinHeight="240""

Now the Source Smooth Streams are encoded using H.264 video codec and AAC as Audio codec. I found at below URL, that audiostreamindex and audiostreamcount properties are for WMV type only and that killed my only left hope. http://msdn.microsoft.com/en-us/library/microsoft.web.media.smoothstreaming.smoothstreamingmediaelement_properties(v=vs.90).aspx

Can any body help me on How I can detect the currently playing language in video, and then I want to put an event handler or "Users action of changing language", once that event i s fired, I want to change the currently playing audio track to the selected one.

Tarun
  • 517
  • 4
  • 9
  • 24
  • BTW I was able to parse and find out the available list of language tracks available in source manifest file- – Tarun May 01 '13 at 13:42
  • If S.Type = Windows.Media.MediaStreamType.Audio Then ' languages.Add(count.ToString, S.Attributes("Name")) 'listLanguages.Add(S.Attributes("Name") Language = New Language() Language.LanguageId = count Language.LanguageName = S.Attributes("Name").ToString listLanguages.Add(Language) count = count + 1 End If – Tarun May 01 '13 at 13:43
  • Basically I was hoping to create something like this -. http://player.smooth.vertigo.com/ , Try with source video as http://ecn.channel9.msdn.com/o9/content/smf/smoothcontent/elephantsdream/Elephants_Dream_1024-h264-st-aac.ism/manifest – Tarun May 01 '13 at 13:44

2 Answers2

3

I suggest to use Silverlight Media Framework, it really simplifies development of video applications. You can download its source code here: http://smf.codeplex.com/downloads/get/386528.

However, you can do some things without framework

  • How I can detect the currently playing language in video

Here is the code:

var currentSegment = mediaElement.ManifestInfo.Segments[mediaElement.CurrentSegmentIndex.Value];
var currentAudioStream = currentSegment.SelectedStreams.Where(i => i.Type == MediaStreamType.Audio).FirstOrDefault()
  • I want to change the currently playing audio track to the selected one

Something like this:

foreach (var segment in mediaElement.ManifestInfo.Segments)
{
    var newStreams = new List<StreamInfo>();
    // use current video streams
    var selectedVideoStreams = segment.SelectedStreams.Where(i => i.Type != MediaStreamType.Audio).ToList();
    newStreams.AddRange(selectedVideoStreams);
    // add a new audio stream
    newStreams.Add(newAudioStream);
    // replace old streams by new ones
    segment.SelectStreamsAsync(newStreams);
}
vortexwolf
  • 13,967
  • 2
  • 54
  • 72
  • Cool! This method works for me, contrary to the solution with setting `AudioStreamIndex` property, described [here](http://www.w3.org/WAI/GL/WCAG20-TECHS/SL1.html). Btw, `AudioStreamCount` always returns `1` for me, even if there are multiple audio streams. – s.ermakovich Aug 13 '13 at 09:21
2

If you are using SMF, here is the easiest solution:

private CustomPlayer SetAudioStreamLanguage(string languageCode)
{
    const string languageAttributeKey = "Language";

    if (AvailableAudioStreams.Count() < 2) return this;

    var languageCode = new CultureInfo(languageCode).ThreeLetterISOLanguageName();
    if (languageCode == null)
    {
        throw new Exception(string.Format("Audio stream language code {0} cannot be converted to three-letter ISO language code.", languageCode));
    }

    StreamMetadata newAudioStream =
        AvailableAudioStreams.FirstOrDefault(
            s =>
                s.Attributes.ContainsKey(languageAttributeKey) &&
                s.Attributes[languageAttributeKey].Equals(languageCode, StringComparison.InvariantCultureIgnoreCase));

    if (newAudioStream == null) return this;

    SelectedAudioStream = newAudioStream;
    return this;
}

This method should be called after MediaOpened event has been fired.

NOTE: CultureInfo.ThreeLetterISOLanguageName() method does not exist in Silverlight. You can find it's sample implementation in this answer.

Community
  • 1
  • 1
s.ermakovich
  • 2,641
  • 2
  • 26
  • 24