Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7497525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:07:56+00:00 2026-05-29T19:07:56+00:00

I am using the following library to stream YouTube videos to an Android application.

  • 0

I am using the following library to stream YouTube videos to an Android application.

http://code.google.com/p/android-youtube-player/source/browse/trunk/OpenYouTubeActivity/src/com/keyes/youtube/OpenYouTubePlayerActivity.java?r=3

I am successfully able to play videos on HTC and Motorola phones over 3G and Wifi. However, on Samsung Galaxy (Epic 4G) and Samsung Galaxy II phones I am only able to play using Wifi. 3G gives me this error: “Cannot play video. Sorry this video cannot be played.”

I have tried forcing low quality YouTube streaming, but this did not help. I see in my log that Start() is being called in both cases (3G/Wifi). Is this an issue with VideoView? Is there a workaround?

Edit 2

The videos are coming from YouTube API. I have attempted using embedded and normal streams, as well as lowest quality stream available (varying per video). Also, I do not think it is an encoding issue since the same videos play correctly using Wifi.

Edit 1

I also receive the following output regardless of wether video plays using Wifi or does not using 3G.

01-30 15:22:38.305: E/MediaPlayer(3831): error (1, -1)
01-30 15:22:38.305: E/MediaPlayer(3831): callback application
01-30 15:22:38.305: E/MediaPlayer(3831): back from callback
01-30 15:22:38.309: E/MediaPlayer(3831): Error (1,-1)

According to this Link, these errors means the following (I think):

/*
 Definition of first error event in range (not an actual error code).
 */
const PVMFStatus PVMFErrFirst = (-1);
/*
 Return code for general failure
 */
const PVMFStatus PVMFFailure = (-1);
/*

/*
 Return code for general success
 */
const PVMFStatus PVMFSuccess = 1;
/*

Further adding confusion.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T19:07:57+00:00Added an answer on May 29, 2026 at 7:07 pm

    Yes, as you are thinking, this is a issue in VideoView, similar issues also appear in MediaPlayer, and I’ve encountered similar and strange issues as you did, I had problems when the video was played only on 3G and not on Wi-Fi. This usually happens on 2.1 and some 2.2 devices, but not on higher API levels as I’ve seen so far.

    So what I can recommend is do the following :

    First check if the running device may be one that can have issues, something like this :

    //Define a static list of known devices with issues
    static List sIssueDevices=Arrays.asList(new String[]{"HTC Desire","LG-P500","etc"});
    
    if(Build.VERSION.SDK_INT<9){
         if(sIssueDevices.contains(Build.Device){
             //This device may have issue in streaming, take appropriate actions
         }
    }
    

    So this was the simplest part, to detect if the running device may have issues in streaming the video. Now, what I did and may also help you, is buffer the video from Youtube in a file on the SDCard and set that file as the source for your VideoView. I will write some code snippets to see how my approach was :

    private class GetYoutubeFile extends Thread{
        private String mUrl;
        private String mFile;
        public GetYotubeFile(String url,String file){
            mUrl=url;
            mFile=file;
        }
    
        @Override
        public void run() {
            super.run();
            try {
    
                File bufferingDir=new File(Environment.getExternalStorageDirectory()
                        +"/YoutubeBuff");
    
                File bufferFile=new File(bufferingDir.getAbsolutePath(), mFile);
                //bufferFile.createNewFile();
                BufferedOutputStream bufferOS=new BufferedOutputStream(
                                          new FileOutputStream(bufferFile));
    
                URL url=new URL(mUrl);
                URLConnection connection=url.openConnection();
                connection.setRequestProperty("User-Agent", "Mozilla");
                connection.connect();
                InputStream is=connection.getInputStream();
                BufferedInputStream bis=new BufferedInputStream(is,2048);
    
                byte[] buffer = new byte[16384];
                int numRead;
                boolean started=false;
                while ((numRead = bis.read(buffer)) != -1 && !mActivityStopped) {
                    //Log.i("Buffering","Read :"+numRead);
                    bufferOS.write(buffer, 0, numRead);
                    bufferOS.flush();
                    mBuffPosition += numRead;
                    if(mBuffPosition>120000 &&!started){
                        Log.e("Player","BufferHIT:StartPlay");
                        setSourceAndStartPlay(bufferFile);
                        started=true;
                    }
    
                }
                Log.i("Buffering","Read -1?"+numRead+" stop:"+mActivityStopped);
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    
    public void setSourceAndStartPlay(File bufferFile) {
        try {
            mPlayer.setVideoPath(bufferFile.getAbsolutePath());
            mPlayer.prepare();
            mPlayer.start();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    

    Another issue will arise when the VideoView has stopped playing before the end of file, because not enough was buffered in the file. For this you need to set an onCompletionListener() and if you are not at the end of the video, you should start again the video playback from the last position :

    public void onCompletion(MediaPlayer mp) {
        mPlayerPosition=mPlayer.getCurrentPosition();
        try {
            mPlayer.reset();
            mPlayer.setVideoPath(
                 new File("mnt/sdcard/YoutubeBuff/"+mBufferFile).getAbsolutePath());
            mPlayer.seekTo(mPlayerPosition);
            mPlayer.start();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    
    }
    

    In the end, of course the GetYoutubeFile thread is started in the onCreate() method :

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //init views,player,etc
        new GetYoutubeFile().start();
    }
    

    Some modifications and adaptation I think will have to be done for this code, and it may not be the best approach, but it helped me, and I couldn’t find any alternative.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am configuring django for using django admin tool, following steps in webpage http://www.ibm.com/developerworks/linux/library/l-django/?S_TACT=105AGX52&S_CMP=cn-a-l
I'm using the WindowsMedia library found here: http://www.ernzo.com/soundstudio.aspx The sample code had the ability
I'm using the following library https://github.com/Leonidas-from-XIV/node-xml2js To convert XML to JSON. After conversion console.log
I compiled the following code as a shared library using g++ -shared ... :
I'm using the boto library in Python to connect to DynamoDB. The following code
I am using Codeigniter message library. In my controller I have the following code
I'm using the following code to hide stderr on Linux/OSX for a Python library
I am using the MongoDB PHP Library and have the following query array Array
I've started using Enterprise Library and have the following questions: 1)How do I add
Anyone out there using the FTUtils library for iPhone development? Following the instructions here

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.