3

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?

peterh
  • 11,875
  • 18
  • 85
  • 108
JaVadid
  • 7,107
  • 13
  • 42
  • 54
  • why do you get such error?? what if i want to play a video placed in res/raw folder? – poojan9118 Jul 15 '10 at 12:12
  • You can very well play the video by the method described above! I got the error bcoz of my hardwares configuration which is was lower than the minimum needed configuration! Hope this helps you! – JaVadid Jul 16 '10 at 09:39

3 Answers3

4

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...

JaVadid
  • 7,107
  • 13
  • 42
  • 54
1

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.

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
0

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • thanx friend... by the way wat i wanted to do exactly is play a specific video wen user clicked a button... is it possible 4 us to place a video in the package such that wen the user installs our package it'll automatically be copied to the SD Card??? so dat i can play it 4m there... – JaVadid Feb 01 '10 at 05:34