I am using the following library to stream YouTube videos to an Android application.
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.
Yes, as you are thinking, this is a issue in
VideoView, similar issues also appear inMediaPlayer, 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 :
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
SDCardand set that file as thesourcefor yourVideoView. I will write some code snippets to see how my approach was :Another issue will arise when the
VideoViewhas stopped playing before the end of file, because not enough was buffered in the file. For this you need to set anonCompletionListener()and if you are not at the end of the video, you should start again the video playback from the last position :In the end, of course the
GetYoutubeFilethread is started in theonCreate()method :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.