Notification texts go here Contact Us Buy Now!

Play music song from Gdrive on website or blogger ,

Play music song from Gdrive on website or blogger
How to Play Google Drive Music on a Website or Blogger

How to Play Google Drive Music on a Website or Blogger

Hosting music or audio files directly on your own website server can quickly consume your bandwidth and storage limits. Google Drive offers a fantastic, free alternative for hosting your MP3 files. However, because Google Drive is designed as a file-storage service rather than a dedicated media-streaming server, you cannot simply copy and paste the default share link into your website's code.

To make your Google Drive audio play smoothly on a custom HTML website or a Blogger blog, you have to modify the link and use specific HTML tags.

Below is a comprehensive guide explaining exactly how to achieve this, complete with copyable demo codes, an explanation of two different methods, and step-by-step instructions for implementation.

Step 1: Prepare Your Audio File on Google Drive

Before writing any HTML code, you must ensure your audio file is accessible to the public and you need to extract its unique "File ID."

  1. Upload the File: Log into your Google Drive and upload your MP3 or WAV file.
  2. Change Permissions: Right-click the uploaded audio file and select Share.
  3. Make it Public: Under "General access," change the setting from "Restricted" to "Anyone with the link". Make sure the role is set to Viewer. Click "Done".
  4. Copy the Link: Right-click the file again and select Copy link.
  5. Extract the File ID: Paste the link into a text editor like Notepad. It will look something like this:
    https://drive.google.com/file/d/1AbC2dE3fG4H5iJ6kL7mN8oP9qR0sT1uV/view?usp=sharing

The File ID is the long string of letters and numbers located between /d/ and /view. In the example above, the File ID is: 1AbC2dE3fG4H5iJ6kL7mN8oP9qR0sT1uV. Keep this File ID handy; you will need it for the codes below.

Method 1: The Google Drive <iframe> Player (Recommended)

This is the most reliable method. It uses Google Drive's native preview player. Because the player is hosted by Google, you won't run into cross-origin (CORS) browser blocking issues, which frequently happen with direct streaming.

How it works: You replace the standard view URL with a preview URL and embed it inside an HTML <iframe> tag.

Copyable Demo Code: The Iframe Player

<!-- Google Drive Iframe Audio Player -->
<iframe 
    src="https://drive.google.com/file/d/YOUR_FILE_ID_HERE/preview" 
    width="100%" 
    height="100" 
    frameborder="0" 
    allow="autoplay; encrypted-media" 
    title="Audio Player">
</iframe>

How to customize this code:

  • YOUR_FILE_ID_HERE: Replace this exact text with the File ID you extracted in Step 1.
  • width="100%": This makes the player responsive, stretching to fit the width of your blog post or website container. You can change this to a fixed pixel value (e.g., width="400").
  • height="100": Google's preview window requires a bit of height. 100 pixels is generally enough to show the play bar without showing too much blank black space.
  • frameborder="0": Removes the ugly default border around the iframe.

Method 2: The Native HTML5 <audio> Tag

If you want a cleaner, more minimalist audio player that perfectly matches standard web design, you can use the HTML5 <audio> tag.

Important Disclaimer: Google actively discourages using Google Drive as a direct content delivery network (CDN). Browsers like Chrome and Safari have strict cross-site tracking protections that sometimes block direct audio streams from Google Drive. This method is cleaner, but it occasionally fails to load on some user devices due to these browser security settings.

How it works: You modify the Google Drive link to force a direct download endpoint and feed that into the src attribute of your audio tag.

Copyable Demo Code: The Native HTML5 Player

<!-- Native HTML5 Audio Player via Google Drive -->
<audio controls preload="metadata" style="width: 100%; max-width: 500px;">
    <source src="https://drive.google.com/uc?export=download&id=YOUR_FILE_ID_HERE" type="audio/mpeg">
    Your browser does not support the audio element.
</audio>

How to customize this code:

  • YOUR_FILE_ID_HERE: Replace this with your actual File ID.
  • controls: This essential attribute tells the browser to display the play, pause, and volume buttons. If you remove this, the player will be invisible.
  • preload="metadata": This is a best practice. It tells the browser to only load the basic data of the file (like the length of the song) when the page loads, saving bandwidth. The actual song only downloads when the user clicks play.
  • style="...": This CSS ensures the player looks good on both desktop and mobile screens.
  • type="audio/mpeg": Keep this if your file is an MP3. If it's a WAV file, change it to type="audio/wav".

How to Embed the Code in Blogger

Blogger makes it very easy to insert custom HTML into your blog posts or pages.

  1. Log in to your Blogger dashboard.
  2. Click on Posts or Pages and create a New Post.
  3. In the post editor, look at the top left corner just beneath the title bar. You will see a pencil icon (Compose view). Click it and select HTML view (< > icon).
  4. The editor will change to show the raw code of your post.
  5. Paste either the Iframe code or the HTML5 code into the editor exactly where you want the player to appear.
  6. Make sure you have replaced YOUR_FILE_ID_HERE with your actual Google Drive File ID.
  7. Switch back to Compose view (the pencil icon). You will see a placeholder block where your audio player is located.
  8. Click Preview to test the audio, and then click Publish.

How to Embed the Code on a Custom HTML Website

If you are building your own website from scratch using HTML, CSS, and JavaScript, embedding the player is just as straightforward.

  1. Open your .html file (e.g., index.html) in your preferred code editor.
  2. Locate the <body> section of your code.
  3. Paste the copyable code snippet into the structural layout where you want it to appear.
  4. Save the file and open it in your web browser to test.

Troubleshooting and Best Practices

  • Autoplay Restrictions: You might be tempted to add autoplay to your <audio> tag so the music plays as soon as the visitor loads the page. Do not do this. Modern browsers strictly block audio from autoplaying unless the audio is muted or the user has interacted with the page first.
  • Google Drive Limits: While Google Drive is free, it does have bandwidth limits. If thousands of people try to play your song at the exact same time, Google may temporarily lock the file for 24 hours. If you expect high traffic, consider a dedicated host like SoundCloud or Amazon S3.
  • File Formats: Always try to use .mp3 files. MP3 is universally supported across all browsers and devices. Formats like .wav are uncompressed, resulting in massive file sizes that take too long to buffer and load.
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.
NextGen Digital Welcome to WhatsApp chat
Howdy! How can we help you today?
Type here...