android video, hear sound but no video

前端 未结 6 1793
情书的邮戳
情书的邮戳 2020-12-07 01:52

I have tried several different examples but I cannot get any video to show. I hear sound but no video. I thought maybe I just had a incorrect video format so I downloaded a

相关标签:
6条回答
  • 2020-12-07 02:16

    If you are using the emulator, it may not work. The emulator lacks the hardware acceleration available in Android devices. For example, on a 2.6GHz Core 2 Duo, I sometimes can get a video to play back, but not always. On slower machines, video playback never works. On a 2.5GHz Core 2 Quad, I always get video playback. That being said, I usually test video playback on actual devices.

    I am also uncertain if video playback works from raw resources. I strongly encourage you to try using a video from a file on the SD card first.

    With respect to videos that definitely work, I know that "Documentaries and You" and "Music for our Grandchildren" from here work in their MP4 forms.

    0 讨论(0)
  • 2020-12-07 02:27

    You can get a full example by looking at the Android ApiDemo sample application (look at the example under 'Media'): http://developer.android.com/resources/samples/ApiDemos/index.html

    As for a sample movie to use with the demo, I've used links YouTube's mobile site with success.

    0 讨论(0)
  • 2020-12-07 02:32

    I ran into the same problem. I was able to fix it by changing SurfaceView to VideoView in the XML layout file. Keep all the rest of the code the same. That worked for me, don't know why.

    0 讨论(0)
  • 2020-12-07 02:34

    Whether a given video file will play in a given player depends on three things:

    • The video container format (file type).
    • The codec the video (and potentially audio) streams encoding; your player's support for that combination of container format and codec
    • The codec and player/device support for it is almost certainly the cause of the inconsistent results you've seen. (A codec, if you didn't know, is basically a repeatable mathematical formula that tells your system how to turn bits and bytes packed into a file into moving pictures(and back again, for that matter))
    0 讨论(0)
  • 2020-12-07 02:40

    This is an old problem but my answer may help someone.

    To support old versions of Android you need to add this line :

    videoHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    
    0 讨论(0)
  • 2020-12-07 02:41

    You class must implement SurfaceHolder.Callback and call methods setDisplay, prepare and etc only after you get in surfaceCreated. Also you may need to change type of surface holder to SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS. Like this:

    import android.view.SurfaceHolder.Callback;
    
    public class TestActivity extends Activity implements Callback {
    
    // ...
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            // ...
            mSurfaceView = (SurfaceView)findViewById(R.id.yousurfaceview); 
            holder = mSurfaceView.getHolder();
            holder.addCallback(this);
            holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        }
    
    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        try {
            mp.setDisplay(holder);
            mp.setDataSource(somesource);
            mp.prepare();
            mp.start();
            // etc...
        } catch (IOException e) {
            } catch (IllegalArgumentException e) {
            } catch (IllegalStateException e) {
        }
    
    }
    
    // ...
    }
    

    If you try it in OnCreate you got nothing as result, because Surface is not yet created...

    0 讨论(0)
提交回复
热议问题