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.
This message often cames from the inappropriate encoding of the video ("Cannot play video. Sorry this video cannot be played.") I was struggling with videoview for a while , now the correct encoded videos play on all tested devices, even when using Wifi or 3G. Let em know if you want to know how to encode the videos. And for streaming the videos I used the demo from android sdk apis and it works flawless.
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
SDCard
and set that file as thesource
for yourVideoView
. I will write some code snippets to see how my approach was :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 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
GetYoutubeFile
thread 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.
I have tackle with this problem in my own way.First every time read your log cat.If you got
that means you will get
sorry,this video can not play message
.So in this case finish that activity, give custom progress bar and download video.Then after downloading save it in temporary folder then play it.After playing delete that folder.To reading log cat---
Read this answer too. although it is just user experience not linked to app.but it happens sometimes in default application also
Heaps of videos, even if I have full 3G network coverage, will say "Sorry, this video cannot be played". One day, I got so pissed off with it, I just kept pressing 'Okay' to dismiss the message, and then pressed the video again only to see the "Sorry, this video cannot be played" message again. I repeated this process (in my blind anger), but eventually, after about 5 tries, the video decided to miraculously play!
This method pretty much works for me every time. Most videos won't want to play the first time, but eventually if I am just persistent, and keep telling it to play even though it tells me it 'can't' play the video, it will play! Although, some videos i've had to press 'Okay', press the video, press 'Okay', press the video etc... for like 20 times before it actually decided to play. Those times, I have been incredibly close to getting my phone and throwing it down on the floor because of how shitty I am with how youtube won't work.
I wish there was a way to fix this problem. No one seems to have come up with a solution. Everyone just says "oh yeah I have the same problem" but no one contributes anything. GOOGLE, SOLVE THIS PROBLEM ON YOUR PHONES. THIS SEEMS TO BE HAPPENING WORLDWIDE, ON A RANGE OF ANDROID PHONES.