clappr-rtmp-plugin icon indicating copy to clipboard operation
clappr-rtmp-plugin copied to clipboard

question How can i find metadata in a video/audio using OSMF player actionscript

Open publicocean0 opened this issue 7 years ago • 0 comments

I m interested to find metadata inside video/audio: in particular if stream is a video or a audio , name, videoDimentions,texttrack languages.Could you give a sugestion how to do?

I tried also to add cues detection in your code.

if (!mediaElement) {
          var streamType:String = (isLive ? StreamType.LIVE : StreamType.RECORDED);
    
          urlResource = new StreamingURLResource(url, streamType, NaN, NaN, null, useAppInstance, null, proxyType);

          var startLevel:int = int(this.root.loaderInfo.parameters.startLevel);

          if (this.root.loaderInfo.parameters.switchRules != "") {
            var switchRules:Object = JSON.parse(this.root.loaderInfo.parameters.switchRules.replace(/&quote;/g, '"'));
            urlResource.addMetadataValue(MetadataNamespaces.RESOURCE_INITIAL_SWITCH_RULES, switchRules);
          }

          if (startLevel > -1) {
            urlResource.addMetadataValue(MetadataNamespaces.RESOURCE_INITIAL_INDEX, startLevel);
          }

          var pluginResource:MediaResourceBase = new PluginInfoResource(new SMILPluginInfo());

          // Load the plugin.
          mediaFactory.loadPlugin(pluginResource);

          //create new MediaPlayer - it controls your media provided in media property
          mediaPlayer = new MediaPlayer();

          mediaPlayer.bufferTime = this.root.loaderInfo.parameters.bufferTime;
          mediaPlayer.autoPlay = autoplay;
          mediaPlayer.autoDynamicStreamSwitch = this.root.loaderInfo.parameters.autoSwitch == 'true';
          mediaPlayer.addEventListener(TimeEvent.CURRENT_TIME_CHANGE, onTimeUpdated);
          mediaPlayer.addEventListener(TimeEvent.DURATION_CHANGE, onDurationUpdated);
          mediaPlayer.addEventListener(TimeEvent.COMPLETE, onFinish);
          mediaPlayer.addEventListener(MediaErrorEvent.MEDIA_ERROR, onMediaError);
          mediaPlayer.addEventListener(DynamicStreamEvent.SWITCHING_CHANGE, onLevelSwitching);

          mediaElement = mediaFactory.createMediaElement(urlResource);

          mediaElement.addEventListener(MediaElementEvent.TRAIT_ADD, onTraitAdd);
          mediaElement.addEventListener(MediaElementEvent.METADATA_ADD, onMetadataAdd);

          mediaContainer.addMediaElement(mediaElement);

          mediaPlayer.media = mediaElement;

          //Set the player scaling
          playerScaling(this.root.loaderInfo.parameters.scaling);

          addChild(mediaContainer);
          resize();


          _changeStateAndNotify('PLAYING_BUFFERING')
          _triggerEvent('playbackready');
        }
      } catch (err:Error) {

        debugLog('Catch error: 1' + err.message+' '+err.getStackTrace());
        _changeStateAndNotify('ERROR')
      }
    }

     private function onMetadataAdd(event:MediaElementEvent):void
        {
            if (event.namespaceURL == CuePoint.DYNAMIC_CUEPOINTS_NAMESPACE)
            {
                var timelineMetadata:TimelineMetadata = videoElement.getMetadata(CuePoint.DYNAMIC_CUEPOINTS_NAMESPACE) as TimelineMetadata;
                timelineMetadata.addEventListener(TimelineMetadataEvent.MARKER_TIME_REACHED, onCuePoint);
            }
        }

    private function onCuePoint(event:TimelineMetadataEvent):void
        {
            var cuePoint:CuePoint = event.marker as CuePoint;
             _triggerEvent('oncue',JSON.stringify(cuePoint));

        }

publicocean0 avatar Jun 14 '17 15:06 publicocean0