Media entity audio currently supports only local audio files. It would be nice to also support remote audio streams. We could do that by using link fields.

Comments

slashrsm created an issue. See original summary.

slashrsm’s picture

Status: Active » Needs review
StatusFileSize
new6.87 KB
slashrsm’s picture

StatusFileSize
new6.87 KB
new502 bytes

Fixed a typo.

slashrsm’s picture

StatusFileSize
new7.75 KB
new896 bytes

Add schema.

berdir’s picture

  1. +++ b/media_entity_audio.module
    @@ -31,17 +37,41 @@ function media_entity_audio_preprocess_media_audio_file_formatter(&$vars) {
    +  $vars['sources'] = array_map(function ($item) {
    +    return [
    +      'url' => $item,
    +      'type' => _media_entity_audio_map_mime(\Drupal::service('file.mime_type.guesser')->guess($item)),
    +    ];
    +  }, $vars['sources']);
    

    this is a bit hard to read, unclear what $item is, maybe store $guesser in a variable so the line is a bit shorter and easier to read? inside or outside, could also be outside with a use ($mime_type_guesser).

  2. +++ b/media_entity_audio.module
    @@ -31,17 +37,41 @@ function media_entity_audio_preprocess_media_audio_file_formatter(&$vars) {
    +function _media_entity_audio_map_mime($mime) {
    

    not a big fan of _underscore functions, but this is just extracted out to avoid duplication, so fine I guess

  3. +++ b/src/Plugin/Field/FieldFormatter/AudioStreamHTML5.php
    @@ -0,0 +1,88 @@
    + * @FieldFormatter(
    + *   id = "audio_stream_html5",
    + *   label = @Translation("Audio Stream (HTML5)"),
    + *   field_types = {
    + *     "link"
    

    in jw_player I used the same formatter for both, but quite possibly easier to separate here.

    Especially since something like this might actually land in core as part of #2831944: Implement media source plugin for remote video via oEmbed (did not check if that's just video or also audio), so might not even be needed for 8.x-2.x?

berdir’s picture

Ah the core issue seems to focus on oembed support, which then wouldn't cover this. That said, core (8.5.x I think) got audio and video html5 formatters recently, so that *could* possibly be also extended there.

berdir’s picture

slashrsm’s picture

StatusFileSize
new7.79 KB
new825 bytes

#5.1 - Refactored a bit.
#5.3 - Merging would require quite some refactoring of the existing formatter. Maybe something we can do for 2.x since it is still in alpha?

slashrsm’s picture

StatusFileSize
new1.41 KB
new7.79 KB

Started porting to 2.x. Source plugin part is pretty straightforward. Formatter part needs work, but it seems that we could simply deprecate it based on #1174892: File field formatters for rich media display with <video> and <audio> HTML5 elements. and #2927166: Allow HTML5 video/audio formatters for link fields on Media entities if the latter lands in core.

1.x patch is identical to #7. Uploaded renamed file for clarity.

berdir’s picture

That will only get into 8.5.x I think, so unless we want to wait that long (and it won't be possible to use that patch in 8.4.x), we probably still need those formatters here, at least temporary?

slashrsm’s picture

StatusFileSize
new7.87 KB
new7.08 KB

Added formatter to the 2.x patch.

berdir’s picture

StatusFileSize
new25.54 KB

This is the first iteration of a patch that only keeps support for streams, as a new audio_stream source plugin. Includes an update function that converts the existing ones either to audio_file (core) or audio_stream, including updating the view display config for audio_file.

The update function does not automatically uninstall itself, but sites may chose to do so if they only used audio files.

This will become a new 8.x-3.x branch.

berdir’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev
berdir’s picture

StatusFileSize
new32.5 KB

A binary patch for the removed fallback thumbnail (core has a audio.png too)

berdir’s picture

StatusFileSize
new25.54 KB
new565 bytes

Using the correct test base class now.

berdir’s picture

StatusFileSize
new32.5 KB

Forgot --binary again.

berdir’s picture

StatusFileSize
new32.51 KB
new867 bytes

And fixing the test.

  • Berdir committed c37f467 on 8.x-3.x
    Issue #2927099 by slashrsm, Berdir: Support audio streams
    
berdir’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.