And*_*ndy 2 java video android
我要做的是播放从外部SD卡中检索到的第一个视频,这个视频在我的T-Mobile G2上被证明是手机的示例视频.现在我认为,因为它在手机视频播放器中播放,所以在我的测试应用中使用VideoView进行播放没有任何问题.
怎么错...
我得到的只是音频播放.我很确定代码都很好.毕竟它很简单.
我能想到的是,手机视频播放器可能会使用一些支持更多视频格式的原生播放功能吗?
我也尝试过播放mv4(实际上是MP4文件)和来自这个网站http://support.apple.com/kb/HT1425的3gp文件,但是将它们推送到模拟器SDCard,但两者都表现出同样的问题.音频,但没有视频!
实际上,我在某个地方错过了许可吗?
其他人可以解释这种行为吗?
码:
public class Video extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.video);
// Get the external storage state
String state = Environment.getExternalStorageState();
// Check if we can read it in
if (Environment.MEDIA_MOUNTED.equals(state)==false&&
Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)==false)
{
// We can't read from the memory card, so warn and return;
Toast toast = Toast.makeText(this,
"The SD card is either missing or not in a readable state.", Toast.LENGTH_LONG);
toast.show();
return;
}
// Get a cursor to the video files
Cursor cc = this.getContentResolver().query(
MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
null, null, null, null);
// Get the video column index
int videoIDColumn = cc.getColumnIndex(MediaStore.Video.VideoColumns._ID);
// Iterate though the videos pointed to by the cursor
if (cc.moveToFirst())
{
int videoID = cc.getInt(videoIDColumn);
Uri videoPath = Uri.withAppendedPath(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,String.valueOf(videoID));
// Log and add an image to the view
Log.i("Video Found",videoPath.toString());
VideoView videoView = (VideoView)findViewById(R.id.VideoTest);
videoView.setVideoURI(videoPath);
videoView.start();
}
else
{
Toast toast = Toast.makeText(this,
"Can't find a video to play.", Toast.LENGTH_LONG);
toast.show();
}
}
}
Run Code Online (Sandbox Code Playgroud)
提前致谢!
安迪
**更新
我尝试使用Android 1.5和1.6,问题仍然存在.
此外,只是检查了logcat,我没有得到任何其他文件的任何错误,但对于.3gp我得到以下错误:
07-02 10:53:31.181: INFO/Video Found(235): content://media/external/video/media/2
07-02 10:53:31.383: VERBOSE/VideoView(235): reset duration to -1 in openVideo
07-02 10:53:31.541: INFO/ActivityManager(58): Displayed activity com.dvl.testing/.screens.Video: 533 ms (total 533 ms)
07-02 10:53:31.693: WARN/PlayerDriver(31): Using generic video MIO
07-02 10:53:31.883: ERROR/SW_DEC(31): PV SW DECODER is used for MPEG4
07-02 10:53:31.922: DEBUG/AudioSink(31): bufferCount (4) is too small and increased to 12
07-02 10:53:32.322: INFO/ARMAssembler(58): generated scanline__00000077:03010104_00000004_00000000 [ 22 ipp] (41 ins) at [0x2166f8:0x21679c] in 3379159 ns
Run Code Online (Sandbox Code Playgroud)
对任何人都有意义吗?
哇,有时我讨厌android文档.
事实证明,在我的情况下,我在xml中为VideoView指定了背景颜色,但不是我假设在视频加载/缓冲时显示的背景颜色,它实际上是前景并且正在呈现在在它背后完美播放的视频!大声笑
如此改变:
<VideoView
android:id="@+id/VideoTest"
android:background="#FF00FF00"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</VideoView>
Run Code Online (Sandbox Code Playgroud)
至
<VideoView
android:id="@+id/VideoTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</VideoView>
Run Code Online (Sandbox Code Playgroud)
对我有用,我的视频现在正在显示!:)
希望这有助于某人!
安迪.