android multiple videoView problem, Galaxy Tab specific - android

I am having problems with multiple videoViews specifically on Galaxy Tab.
In my app, I have two different video files which I want to play simultaneously. So I designed my app to have two videoViews side by side. Tried to run it on two non Galaxy tabs and it worked. Easy as that.
But then, I tried to test it on my Galaxy Tab and the problem comes out. The two video file doesn't play. At some point, the first video file plays and then stops and pops up the Cannot Play Video error. I spent almost two days looking for the cause of the problem and I failed. That's why I resorted to guessing what could be the cause.
My suspicion was that it cannot render two videos at the same time, so I tried to play only the sound of the first file using MediaPlayer and play the other one in the videoView. And I think my suspicioin was right because it works, the first video file plays only the sound, and the other one plays the full video and the sound.
I am looking for someone with this kind of problem, or someone who knows a workaround for this. I will post my simple code here for you to take a look at it. I would really appreciate your help! Thanks in advance.
junmats.
final videoView v1 = (VideoView) findViewById(R.id.videoView1);
final videoView v2 = (VideoView) findViewById(R.id.videoView2);
Thread th1 = new Thread(new Runnable() {
#Override
public void run() {
Uri uriFile = Uri.parse(myFile);
v1.setVideoURI(uriFile);
v1.start();
}
});
th1.start();
Thread th2 = new Thread(new Runnable() {
#Override
public void run() {
Uri uriFile = Uri.parse(
v2.setVideoURI(uriFile);
v2.start();
}
});
th2.start();

This seems to be dependent on the kernel version so it may not be supported on certain devices... http://code.google.com/p/android/issues/detail?id=17802
You may have to wait for an update.

Related

Can't play video through intent

My app has a photo gallery that displays a constant list of images. I need to add one video to that list (just one, provided by me). This video is inside an expansion file. I would like to let the user decide the video player he wants to use to play the video. So I went for the intent approach:
public void playVideo(View view){
Intent videoint = new Intent(Intent.ACTION_VIEW);
Uri uri = CustomAPEZProvider.buildUri("test.3gp");
Log.d("TEST", uri.toString());
videoint.setDataAndType(uri, "video/*");
startActivity(videoint);
}
My CustomAPEZProvider is the following:
public class CustomAPEZProvider extends APEZProvider {
private static final String AUTHORITY = "com.myapp.package.provider";
#Override
public String getAuthority() {
return AUTHORITY;
}
public static Uri buildUri(String path) {
StringBuilder contentPath = new StringBuilder("content://");
contentPath.append(AUTHORITY);
contentPath.append(File.separator);
contentPath.append(path);
return Uri.parse(contentPath.toString());
}
}
Also, I added this to my manifest:
<provider android:name="com.myapp.package.CustomAPEZProvider"
android:authorities="com.myapp.package.provider" >
android:exported="true"
android:multiprocess="true">
<meta-data
android:name="mainVersion"
android:value="4"/>
</provider>
The provider has this meta-data because the expansion file version differs from the apps version code.
I understand that the file is being found, but the video players are not able to play it. They are launching the can't play this video window (and no errors). I tested it on many devices and with different kinds of videos. The 3gp video I'm using to test can be played just fine from the phone's native gallery.
Line 3 on the playVideo method is printing this
content://com.myapp.package.provider/test.3gp
This is correct, right?
The expansion file has no folders, files are just thrown at root.
Also, I actually need to play this test.3gp video from the patch expansion file. Will there be any difference in that case? I'm eliminating this obstacle for now. I know I should add it to the provider's meta-data.
Some extra information: the expansion file has several audio files that I'm being able to play using a MediaPlayer without any issues. Of course, this is different because in that case I'm doing it by getting an AssetFileDescriptor to the file inside the obb expansion file, whereas with the video I need an Uri, which changes everything.
I read lots of questions with similar problems, but they were not helpful. Does anyone had the same problem?
Workarounds are also welcome. For example, I could accept to use a VideoView if needed.
UPDATE
I've just realised that the video player is not working, even if the file is a resource (inside drawable, raw, or whatever). I did manage to play the video with the code below:
public void playVideo(View view){
Uri uri = CustomAPEZProvider.buildUri("test.3gp");
getWindow().setFormat(PixelFormat.TRANSLUCENT);
VideoView videoHolder = new VideoView(this);
videoHolder.setMediaController(new MediaController(this));
videoHolder.setVideoURI(uri);
setContentView(videoHolder);
videoHolder.start();
}
But this is not exactly what I want, I'd really like to allow the user to choose the video player of his preference. Mainly because I want to free myself from the responsibility to code a nice-to-look-at video player.
I don't think the problem lies anywhere in your code. Or, if it does, it's not your biggest problem.
I think your biggest problem is using a 3GP file. That format is not supported by all devices. You're better off with an MP4. And even then, make sure that it's encoded with a CODEC that all Android devices understand.
I had the same problem (video played without problem with native gallery, but not through intent). How the problem is solved is to add the following line to manifest:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
and give the permission to the installed app.

I cannot change a video using MediaPlayer without reseting

I am working with streaming video and I want to change from one source to another dinamically.
First I set the video uri to the VideoView
view.setVideoURI(myUri);
And I know that I am capable of changing it afterwards by doing (this is in onPrepare method but it could go somewhere else where I have access to the MediaPlayer).
#Override
public void onPrepared(MediaPlayer mp)
{
Uri newUri = getOtherUri();
mp.reset();
mp.setDataSource(getApplicationContext(), newUri);
mp.prepare();
mp.start();
}
The thing is, I want to change the source without reseting the mediaPlayer (I do not want to disturb the user).
I tried to create a new VideoView with the new Uri and then change one object for the other, and likewise with the media player. However, none of that seems to work.
Is it possible to replace a video while it is playing in Android?
Any comments would be appreciated.
There is no option to reset the video without using mediaplayer.stopPlayback() or mediaplayer.reset. The reason is that; the previous object of the mediaplayer has to be released before you can play other video .
I want to change the source without reseting the mediaPlayer (I do not want to disturb the user).
Well, this cannot be achieved as the mediaplayer has to be reset. So there will be lag while changing videos. And to satisfy you, you can see these behavior in any videoplayer app like youtube or mxplayer.
So the only thing you can do is to show progressbar while loading or changing video.
Hope it helps. Cheeers.:)

How can I play videos consecutively using VideoView control?

I have a video playing using the VideoView control,
VideoView vid;
vid = (VideoView)findViewById(R.id.video);
String urlpath = "android.resource://" + getPackageName() + "/" + R.raw.videoviewdemo;
vid.setVideoURI(Uri.parse(urlpath));
vid.start();
which works fine, but I assumed incorrectly that calling setVideoURI() and start() would wait for the first video to finish before playing the second. Is there any way to make the entire video play before moving on to the next line of code? Thanks
(I just started Android/Java programming a few days ago, and haven't written software in ANY language for years, so forgive me if I'm a little slow)
you can always use the completion listener to play the next video.
it will trigger as soon as current video gets finished.
keep track of the currently running video in the global integer.
update it to keep the track of them and get the next video to play
check this link
Listener (or handler) for video finish

Movie Player Android

I have two questions. I create movie player.
This is my code:
VideoView videoView = (VideoView)this.findViewById(R.id.videoView);
MediaController mc = new MediaController(this);
videoView.setMediaController(mc);
videoView.setVideoPath("/sdcard/747.3gp");
videoView.requestFocus();
videoView.start();
As you can see I want to play movies from sd card. To check my results I use emulator 2.2. So this is my first question: always when I want to play movie, he is stuck, but sound from movie is playing correctly. This is emulator error or maybe I am doing something wrong? And second question. I want play movies this way. I execute application and I get List of movies. I choose movie and this movie is playing. How I can do this? Can you write me example? I need help :)
For your first question, this should definitely be emulator's speed problem or problem with your file itself.
And answering your second question, you can go for samples like file explorer which displays all the files from sdcard in a listview and using which you can handle to show only video files.
Here is a example of file explorer,
http://android-er.blogspot.com/2010/01/implement-simple-file-explorer-in.html
http://androidsamples.blogspot.com/2009/06/displaying-list-of-video-files-stored.html
Extract the necessary code from the links and modify it accordingly.

Android not playing Video .mp4

I have prepared a code to just play a simple mp4 file from my res folder. The coding is something like this:
public class VideoPlayer extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.video);
VideoView video = (VideoView)findViewById(R.id.VideoView);
Uri uri = Uri.parse("android.resource://company.software.myapp/"
+ R.raw.myvideo);
MediaController mc = new MediaController(this);
video.setMediaController(mc);
video.setVideoURI(uri);
//video.requestFocus();
video.start();
}
}
Now though there is no error in playing. The activity automatically generates a dialog saying "sorry this video cannot be played", but I can hear the audio and it plays till end. What is the problem?
Thanx a lot commonsware.com... but i found the solution to the problem... And astonishingly its the PC processor which is the culprit... I checked n a higher configuration and guess wat... it worked perfectly fine... though sometimes if we do some processing in the background the dialog box does come up but on clicking ok it starts playing the video after some time...
But i confirm that this technique of playing file from resource is ok as far as i know...
sorry to waste ur precious time in a mundane hardware problem... but hope it'll be useful for other people who get this problem...
Android supports 3gp and mp4 format, but still sometimes there are problems in playing an mp4 content.
one thing what I have found out from my research is that, this might be because the resolution problem with the video.
I think that you should re-size the resolution of your mp4 video. This might help.
I have not attempted to play a video clip out of a resource, and I am not certain that it works.
As a test, put the video clip on the SD card and use that as the source of your video.
If you get the same symptoms, then either the MP4 file has issues or it is something with your test environment (e.g., you are using the emulator and don't have a quad-core CPU).
If the SD card test works, though, then I suspect the problem is packaging it as a resource.

Categories

Resources