简体   繁体   English

Android VideoView 无法在 T-Mobile G2 上播放示例视频(仅音频)

[英]Android VideoView not playing sample video on T-Mobile G2 (just audio)

What I'm trying to do is play the first video retrieved from the external SD card, which on my T-Mobile G2 turns out to be the sample video for the phone.我想要做的是播放从外部 SD 卡中检索到的第一个视频,在我的 T-Mobile G2 上,它是手机的示例视频。 Now I assumed that since it plays in the phones video player, that it'd have no problems playing in the VideoView in my test app.现在我假设因为它在手机视频播放器中播放,所以在我的测试应用程序的 VideoView 中播放没有问题。

However, all I get is the audio playing.但是,我得到的只是音频播放。 I'm pretty sure the code is all fine.我很确定代码没问题。 After all, it's pretty simple.毕竟,这很简单。

All I can think is that maybe the phones video player uses some native playback function which supports more video formats?我能想到的是,也许手机视频播放器使用了一些支持更多视频格式的原生播放功能?

I've also tried playing the mv4 (actually an MP4 file) and the 3gp files from this site http://support.apple.com/kb/HT1425 , but pushing them on to the emulator SDCard.我也试过从这个网站http://support.apple.com/kb/HT1425播放 mv4(实际上是一个 MP4 文件)和 3gp 文件,但将它们推送到模拟器 SDCard。 Both of them exhibit the same problem - there is audio, but no video!他们都表现出同样的问题 - 有音频,但没有视频!

Could I be missing a permission somewhere or what could explain this behavior?我是否可能在某处丢失了许可,或者什么可以解释这种行为?

Code:代码:

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();
        }
    }
}

Update更新

I've tried using android 1.5 and 1.6, but the problem still persists.我已经尝试使用 android 1.5 和 1.6,但问题仍然存在。

Also, I just checked logcat and there are no errors for any of the other files, but for the .3gp I get this error:另外,我刚刚检查了 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

Wow, sometimes I hate the android documentation.哇,有时我讨厌 android 文档。

Turns out that in my case, I was specifying a background colour for the VideoView in xml, but instead of being the background colour which I assumed would show while the video is loading / buffering, it was in fact the foreground and being rendered over the video which was playing perfectly behind it!事实证明,在我的情况下,我在 xml 中为 VideoView 指定了背景颜色,但不是我假设在视频加载/缓冲时会显示的背景颜色,它实际上是前景并在在它后面完美播放的视频! lol哈哈

So changing:所以改变:

<VideoView 
  android:id="@+id/VideoTest" 
  android:background="#FF00FF00" 
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
</VideoView>

to

<VideoView 
  android:id="@+id/VideoTest" 
  android:layout_width="wrap_content"
  android:layout_height="wrap_content">
</VideoView>

Works a treat for me and my videos are now showing!对我有用,我的视频现在正在播放! :) :)

Hope this helps someone!希望这可以帮助某人!

Andy.安迪。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM