开发者

Video is not displayed!

I am trying to display video file bt it is not being displayed only audio is coming.Can anyone help me??

This is my code.

The Activity in which list is displayed:

public class AudioPlay extends ListActivity{

    private static final String MEDIA_PATH = new String("/sdcard/");

    private List<String> songs = new ArrayList<String>();

    private MediaPlayer mp = new MediaPlayer();

    private int currentPosition = 0;



    @Override

    public void onCreate(Bundle icicle) {

            super.onCreate(icicle);
      setContentView(R.layout.songlist);

            updateSongList();

    }

    public void updateSongList() {

            File home = new File(MEDIA_PATH);

            if (home.listFiles(new Mp3Filter()).length > 0) {

                    for (File file : home.listFiles(new Mp3Filter())) {

                            songs.add(file.getName());

                    }
              ArrayAdapter<String> songList = new ArrayAdapter<String>(this,

                                    R.layout.song_item, songs);

                    setListAdapter(songList);

            }

    }

    class Mp3Filter implements FilenameFilter {

            public boolean accept(File dir, String name) {

                    return (name.endsWith(".mp3"));

            }

    }

    @Override

    protected void onListItemClick(ListView l, View v, int position, long id) {

            currentPosition = position;

            playSong(MEDIA_PATH + songs.get(position));

    }

    private void playSong(String songPath) {

            try {



                    mp.reset();

                    mp.setDataSource(songPath);

                    mp.prepare();

                    mp.start();



                    // Setup listener so next song starts automatically

                    mp.setOnCompletionListener(new OnCompletionListener() {



                            public void onCompletion(MediaPlayer arg0) {

                                    nextSong();

                            }

                    });

            } catch (IOException e) {

                    Log.v(getString(R.string.app_name), e.getMessage());

            }

    }

    private void nextSong() {

            if (++currentPosition >= songs.size()) {

                    // Last song, just reset currentPosition

                    currentPosition = 0;

            } else {

                    // Play next song

              开发者_如何学C      playSong(MEDIA_PATH + songs.get(currentPosition));

            }

    }
}

The Activity in which videoview is used:

public class videoshow extends Activity{
    public void onCreate(Bundle savedInstance)
    {
        super.onCreate(savedInstance);
        setContentView(R.layout.videoshow);
        //Intent intent = getIntent();
        //Bundle bundle = intent.getExtras();
        VideoView videoview = (VideoView)findViewById(R.id.videoView1);
        MediaController mediaController = new MediaController(this);
               mediaController.setAnchorView(videoview);
        //videoview.setVideoPath(bundle.getString("pos"));
        videoview.setMediaController(new MediaController(this));
        videoview.requestFocus();
        videoview.setVideoPath(MEDIA_PATH);

        videoview.start();
    }

}

Plz help me out


It looks like you're not passing in a Surface to the mediaplayer. The mediaplayer will not know where to render the video unless you specify with setDisplay(SurfaceHolder sh) [look at API].

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜