我正在尝试显示视频文件但它没有显示只有音频即将来临。任何人都可以帮助我吗?
这是我的代码。
显示列表的活动:
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
playSong(MEDIA_PATH + songs.get(currentPosition));
}
}
}
使用videoview的活动:
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帮帮我
答案 0 :(得分:0)
看起来你没有将Surface传递给媒体播放器。除非您使用setDisplay(SurfaceHolder sh)指定[查看API],否则媒体播放器将不知道在何处呈现视频。