Is it possible to display just the progress bar and controls on a YouTube video that is embedded?

I've spent the last few hours trying to figure out how to turn a YouTube video into an audio player, but I haven't had any success. So far, I've come across three main options: 1. Adjust the height of the iframe to 25px, but I find that visually unappealing. 2. Use play and pause buttons instead, but this method lacks a progress bar. 3. I've read somewhere that you can hide the video while keeping the controls visible using CSS, but I couldn't get it to work.

Does anyone know a better way to achieve this?

Edit: I have a potential solution, but I'm encountering some issues. Here's the code:

<html>
  <head>
    <style>
      iframe{
        height:0;
      }
    </style>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="playeroptions.js"></script>
  </head>
  <body>
    <audio id="player2" preload="none" controls>
      <source src="https://www.youtube.com/watch?v={{id}}" type="video/x-youtube">
    </audio>
  </body>
</html> 

In my playeroption.js file, I have the following script:

$(document).ready(function(){
  $('audio').mediaelementplayer();
});

However, on my website, I'm unable to interact with any of the audio player's buttons. How can I resolve this issue? P.S. I'm getting the error message:

Refused to execute script from 'http://127.0.0.1:8000/player/9XvXF1LrWgA/playeroptions.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

Answer №1

As mentioned in the comments, it was noted that even when the iframe is minimized, the video remains visible. This is due to the fact that the video will adjust its size according to the player. A workaround for this issue is to make the player taller than usual. By doing so, the YouTube player will maintain the aspect ratio of the video, resulting in black bars at the top and bottom. To implement this, you can absolutely position the player inside a parent div, hide any overflow, and achieve a cleaner look with just the controls on a black background.

CSS:

.player {
  width: 500px;
  height: 35px;
  overflow: hidden;
  position: relative;
}

.player iframe {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 2000px;
  border: none;
}

HTML:

<div class="player">
   <iframe src="https://www.youtube.com/embed/F4jYWOqHPEA?autoplay=1"></iframe>
</div>

Fiddle: https://jsfiddle.net/8h71453t

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Replace Formik with useFormik to streamline your code

I have implemented Formik/Yup for validation on a page that triggers a GraphQL mutation. The code is functioning as expected: export default function RemoveUserPage() { const [isSubmitted, setIsSubmitted] = useState(false); const [isRemoved ,setIsRemo ...

Using HTML within a JSON string in Java

I need to save the contents of a Java class called MyClass into a text file using JSON for encoding, instead of implementing the Serializable interface. I plan to utilize Google's Gson library, specifically the JsonWriter class. The structure of the M ...

jQuery - Can you identify the mistake in this code?

I've encountered a strange issue while working with jQuery's .get() function. Here is the frontend code snippet... <body> <button title="minor">Minor Armor</button> <br /><br /> <button title="medium">Medium ...

Encountering difficulties accessing props while invoking a component in React

In my project, I've created a component called FilterSliders using Material UI. Within this component, I passed a prop named {classes.title} by destructuring the props with const { classes }: any = this.props;. However, when I try to access this prop ...

Unveiling the magic of Vue Composition API: Leveraging props in the <script setup> tag

I'm currently working on creating a component that takes a title text and a tag as properties to display the title in the corresponding h1, h2, etc. tag. This is my first time using the sweet <script setup> method, but I've encountered a pr ...

Guide to testing Vuex Mutations with Vue-test-utils and Jest

I have reviewed a few tutorials on mocking and testing Vuex actions, but I have struggled to implement them successfully on my own. Despite following the steps outlined in the links provided, I consistently encountered an issue where toHaveBeenCalled would ...

Converting an array of objects into a flat array of objects with Javascript

My data array requires conversion to a flattened array returning new header and data. For instance, the first object contains a name with three data points: "title, first, last." The desired output is: From : { gender: 'male', name: { ...

Verifying Initialization Before Destructing jQuery File Upload

I'm currently working with the blueimps jQuery file upload plugin and I need to delete all existing instances before creating new ones. The issue I'm running into is that I receive an error when attempting something like this: $('.upload&ap ...

How do I prevent the .Collapse class in Twitter Bootstrap from causing navbar elements to disappear on larger screens?

Even the code I copied from getbootstrap.com is experiencing the same issue. Below is my custom code that functions perfectly on mobile devices with the collapsed menu. However, when the page width exceeds 768px, the list items are not displayed. No addi ...

Transferring information via Segments in Ionic 3

I'm facing a challenge where I need to transfer a single ion-card from the "drafts" segment to the "sent" segment by simply clicking a button. However, I am unsure of how to achieve this task seamlessly. Check out this image for reference. ...

Organize intricate JavaScript Arrays

Similar Question: How to sort an array of javascript objects? I'm in the process of transitioning some of my older ActionScript 2.0 code to JavaScript. While most things are running smoothly, I've hit a roadblock when trying to numerically s ...

Automatically update the div every few seconds and pause when it has loaded successfully

I am facing a challenge in creating a div that refreshes automatically every 10 seconds, but stops when it successfully loads. Here is the jQuery script I have developed: <script type="text/javascript"> $(document).ready(function(){ var j = jQuer ...

What is the best way to retrieve specific feature properties in Open Layers 3 on-the-fly?

Within my map, I have two types: Point and Polygon, each with unique properties such as id, door number, and name. I have generated a list of features as follows: var features = new ol.format.GeoJSON().readFeatures(geojsonObject, { featureProjection: & ...

Issue encountered in WebdriverIO: The .getAlertText() method cannot be utilized, displaying the error message "Unresolved function or method getAlertText()"

Currently, I am working on creating automated tests in WebStorm. One of the tasks involves checking if an alert appears to prompt the user. To achieve this, I planned to utilize the .getAlertText(); method. However, I encountered an issue as WebStorm does ...

Tips for resizing a larger image to display only a specific portion in CSS (and incorporating JS if needed)

I need to resize an image that measures 1024x1024 and is segmented into 4 quadrants: My goal is to reduce the size of this image so that quadrant 2 is 256x256 while masking out or hiding the remaining 3 quadrants, displaying only the desired section on th ...

I am struggling to make php redirect work using onclick() function

My PHP button is not redirecting properly. Assuming the page destination is correct, is there anything else that could be causing this issue? echo "<button id=\"create\" onclick=\"location.href('/team/teams.php?op=create');&bso ...

Can you attach a jQuery function to multiple CSS selectors at once?

Is it feasible to bind a mouseout call to two CSS selectors in order to trigger another action when the mouse moves away from both elements simultaneously? ...

Having trouble with CSS3 radio buttons not functioning properly on Firefox?

Does anyone know why my CSS3 pseudo elements are working fine in Chrome, but reverting back to default styling in Firefox for my radio button? Any suggestions? Check out this JSFIDDLE link for reference: JSFIDDLE Here is the HTML code snippet: <input ...

Child components in Angular 2+ successfully animate when entering, but struggle to animate when leaving

One of my sub-components looks like this: @Component({ selector: 'is-time-controlled', templateUrl: './is-time-controlled.html', styleUrls: ['./is-time-controlled.less'], animations: [ trigger( 'myAnimation&a ...

Combining Codeigniter with AJAX for an efficient system

I'm facing an issue with my like system where a user can give more than one like, but only one is being registered in the database. I suspect it's related to AJAX. Here is the button code: <a class="btn btn-xs btn-white" name="btn" onclick=" ...