Exemplo n.º 1
0
 /// <summary>
 /// The <c>&lt;audio></c> tag defines sound, such as music or other audio streams.
 /// Currently, there are 3 supported file formats for the <c>&lt;audio></c> element: MP3, Wav, and Ogg:<remarks> </remarks>
 /// 
 /// For more information see: <see cref="http://www.w3schools.com/tags/tag_audio.asp"/>
 /// </summary>
 /// <param name="builder">Builder for the Html Component</param>
 /// <param name="source">The URI pointing to the audio source<c> [src]</c></param>
 /// <param name="mimeType">
 ///     The MimeType of the audioFile<c> [type]</c> (Optional) <remarks></remarks>
 ///     If left blank the mimetype will be resolved by the file extension
 /// </param>
 /// <param name="autoplay">Specifies that the audio will start playing as soon as it is ready (optional)</param>
 /// <param name="controls">Specifies that audio controls should be displayed (such as a play/pause button etc) (optional)</param>
 /// <param name="loop">Specifies that the audio will start over again, every time it is finished (optional)</param>
 /// <param name="muted">Specifies that the audio output should be muted (optional)</param>
 /// <param name="preload">Specifies if and how the author thinks the audio should be loaded when the page loads<c> [auto|metadata|none]</c> (optional)</param>
 /// <param name="attributes">Standard HTML Attributes (optional)</param>
 /// <returns></returns>
 public static IHtmlElement Audio(this IBuilder builder, 
     Uri source,
     string mimeType = null,
     bool? autoplay = null,
     bool? controls = null,
     bool? loop = null,
     bool? muted = null,
     MediaPreloadType preload = null,
     IHtmlAttributes attributes = null)
 {
     mimeType = CheckFileExtension(source, mimeType);
     var newAttributes = attributes ?? new HtmlAttributes();
     newAttributes.Add("href", source.ToString());
     newAttributes.Add("type", mimeType);
     if(autoplay.HasValue) newAttributes.Add("autoplay", nameof(autoplay));
     if(controls.HasValue) newAttributes.Add("controls", nameof(autoplay));
     if(loop.HasValue) newAttributes.Add("loop", nameof(loop));
     if(muted.HasValue) newAttributes.Add("muted", nameof(muted));
     if(preload != null) newAttributes.Add("preload", preload.ToString());
     return AudioElement(builder, newAttributes);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Check wether the file extension is correct
 /// </summary>
 /// <param name="source">The URI pointing to the audio source<c> [src]</c></param>
 /// <param name="mimeType">
 ///     The MimeType of the audioFile<c> [type]</c> (Optional) <remarks></remarks>
 ///     If left blank the mimetype will be resolved by the file extension
 /// </param>
 /// <returns></returns>
 private static string CheckFileExtension(Uri source, string mimeType)
 {
     var fileExtension = !Path.HasExtension(source.ToString())
         ? null
         : Path.GetExtension(source.ToString()).ToLowerInvariant();
     if (fileExtension != null)
     {
         if (!AllowedAudioExtensions.Contains(fileExtension))
             throw new ArgumentException(
                 $"The extension '{fileExtension}' is not allowed, " +
                 $"the audio element currently supports: [{String.Join("|", AllowedAudioExtensions)}]",
                 nameof(fileExtension));
         mimeType = mimeType ?? MimeMapping.GetMimeMapping(source.ToString());
     }
     return mimeType;
 }