Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <script src="https://cdn.jsdelivr.net/gh/QuentinAndre/AffectiveSamplerJS/lib/affectivesampler.js"></script>
<div id="wrapper">
  <div id="mysamplingtask"></div>
  <div id="user-ratings"></div>
</div>
              
            
!

CSS

              
                #mysamplingtask {
  width: 30%;
  font-size: 1.2em;
}

#user-ratings {
  width: 30%;
  height: 499px;
  padding-left: 10px;
}

#wrapper {
  display: flex;
}

              
            
!

JS

              
                function displayRatings() {
  const ratings = this.getRatingsAsJSON();
  const ratingsDiv = document.getElementById("user-ratings");
  ratingsDiv.innerHTML = "";
  const ratingsKeys = Object.keys(ratings);
  const firstDisplayed = Math.max(0, ratingsKeys.length - 15);
  var i = 0;
  for (k in Object.keys(ratings)) {
    if (i >= firstDisplayed) {
      let span = document.createElement("span");
      span.textContent = "Rating at " + k + " seconds: " + ratings[k];
      ratingsDiv.appendChild(span);
      ratingsDiv.appendChild(document.createElement("br"));
    }
    i++;
  }
}

const aff_sampler = new AffectiveSampler({
  parentId: "mysamplingtask",
  mediaUrl:
    "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4", // The media to show.
  mediaType: "video", // The type of the media, can be "video" or "audio"
  showMediaControls: false, // Whether the show the media controls. If false, only a play/pause button will be displayed.
  canPauseMedia: true,
  sliderMin: -50, // The minimum value of the affective slider
  sliderMax: 50, // The maximum value of the affective slider
  timeResolution: 1, // The time resolution (in seconds) at which to sample. Should not be lower than 1.
  textLabel: "Your current happiness rating is: ", // The label to display next to the current affective rating.
  minLabel: "Sad", // The left anchor of the affective scale.
  maxLabel: "Happy", // The right anchor of the affective scale.
  onInterval: displayRatings, // A function to call when recording a value.
  onMediaEnd: function() {
    console.log("The media has ended");
  } // A function to call when the media ends.
});

              
            
!
999px

Console