On Wed, Mar 4, 2009 at 12:09 AM, zypsg <[email protected]> wrote: > > Hi, A surprising problem occurs when I try to play Video, I can only > hear the sound part of the video. My code snippet is below: > > public class VideoDemo extends Activity { > > public static final int MENU_PLAYER=Menu.FIRST; > public static final int MENU_VIDEO=MENU_PLAYER+1; > private final static String VIDEOURL="/sdcard/10-58-26.3gp"; > /** Called when the activity is first created. */ > �...@override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > // playVideoByVideoView(VIDEOURL); > } > private void playVideoByVideoView(String fileURL){ > // this.getWindow().setFormat(PixelFormat.TRANSLUCENT); > setContentView(R.layout.videoview); > VideoView videoView=(VideoView)findViewById(R.id.surface_view); > > // videoView.setVisibility(SurfaceView.VISIBLE); > videoView.bringToFront(); > videoView.setVideoPath(fileURL); > videoView.setMediaController(new MediaController(this)); > videoView.requestFocus(); > // videoView.start(); > } > private void playVideoByMediaPlayer(String fileURL){ > MediaPlayer mp = new MediaPlayer(); > SurfaceView sv =new SurfaceView(this); > try { > mp.setDataSource(fileURL); > mp.setDisplay(sv.getHolder()); > mp.prepare(); > mp.start(); > } catch (IllegalArgumentException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > mp.release(); > > } catch (IllegalStateException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > mp.release(); > } catch (IOException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > mp.release(); > } > } > �...@override > public boolean onCreateOptionsMenu(Menu menu) { > // TODO Auto-generated method stub > boolean ret= super.onCreateOptionsMenu(menu); > menu.add(0, MENU_PLAYER, 0, "MediaPlayer"); > menu.add(0, MENU_VIDEO, 0, "VideoView"); > return ret; > } > �...@override > public boolean onMenuItemSelected(int featureId, MenuItem item) { > // TODO Auto-generated method stub > boolean ret= super.onMenuItemSelected(featureId, item); > switch(item.getItemId()){ > case MENU_PLAYER: > playVideoByMediaPlayer(VIDEOURL); > > break; > case MENU_VIDEO: > playVideoByVideoView(VIDEOURL); > break; > } > return ret; > } > } > > > > But when I invoke playVideoByVideoView() method in onCreate() ,I can > see the video part. Can anybody tell me why this problem happen? How > can I solve this problem. Thanks Very Much!
Your 'playVideoByMediaPlayer' method doesn't show the video because it has no visible surface to display it on: "new SurfaceView()" does not cause a Surface to be shown on screen, just like "new Button()" would not cause a button to appear on the screen. You have to make the view part of your layout. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

