How to stream only audio data from youtube video on my application?

24,658

Solution 1

It sounds like you are already most of the way there. Your application has a way to list the videos and download selected ones. You just need an infrastructure for playing the audio directly from the video files.

YouTube videos can either be FLV or MP4 files. Inside these files can be MP3 or AAC audio (some other audio codecs are possible, but you won't encounter those on YouTube). This means your app needs to know how to take apart FLV and MP4 files directly, and how to decode MP3 and AAC audio directly to PCM. There are libraries to help with these tasks, depending on your language and platform.

Solution 2

please try extract the audio from video stream using the following code:

// the video URL is the following
    String url = "http://137.110.92.231/~chenyu/BBC.mp4"; 

    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    try {
        mediaPlayer.setDataSource(url);
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        mediaPlayer.prepare(); // might take long! (for buffering, etc)
    } catch (IOException e) {
        e.printStackTrace();
    }
    mediaPlayer.start();
Share:
24,658
Aishwarya Shiva
Author by

Aishwarya Shiva

With over 10 years of experience providing thorough and skillful advice in software development, digital marketing, PC troubleshooting and other tech related issues to both individuals and businesses. Use this VIP link and give me a call for free .NET, C#, ASP.NET, MVC, JAVA, PHP, WCF, WPF etc. consultation: https://clarity.fm/aishwaryashiva/early638

Updated on July 09, 2022

Comments

  • Aishwarya Shiva
    Aishwarya Shiva almost 2 years

    I want to develop an application that will display a list of videos from YouTube and when the user clicks a Youtube video, my application will start playing its audio. I came across a solution to download the YouTube video first and extract audio, but to speed up the process I want to directly transfer the audio bits to my application's audio player instead of video. In other words, I want to stream YouTube audio instead of video in my application.

  • Lucas Sousa
    Lucas Sousa about 3 years
    From where the MediaPlayer class is? Any external library? Please, add more explanation.