1

我尝试使用 Android Videoview 在我的 SD 卡中播放视频。如果 sdcard 有多个视频,它会在我的 sdcard 中播放下一个视频。但是在我的模拟器或智能手机中,该应用程序都无法运行。

我已经添加了权限

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

和一个视频到我的 SD 卡。

以下是我的代码,

package com.example.videotest;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.os.Bundle ;
import android.provider.MediaStore.Video;
import android.app.Activity;
import android.database.Cursor;
import android.view.Menu;
import android.widget.Toast;
import android.widget.VideoView;

 public class MainActivity extends Activity implements OnCompletionListener{
 Cursor mediaCursor=null;
 VideoView videoView=null;
 int dataIdx=0;
@Override
public void onCompletion(MediaPlayer arg0) {
    // TODO Auto-generated method stub
    playNextVideo();            
}       
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    VideoView videoView=(VideoView) findViewById(R.id.videoView1);
    videoView.setOnCompletionListener((OnCompletionListener) this);
    String projection[]=new String[] {Video.Media.DATA};
    mediaCursor=getContentResolver().query(Video.Media.EXTERNAL_CONTENT_URI, projection, null, null, null);
    if(mediaCursor!=null&&mediaCursor.getCount()>0){
           dataIdx=mediaCursor.getColumnIndex(Video.Media.DATA);
           playNextVideo();
    }
}
private void playNextVideo(){
        mediaCursor.moveToNext();
        if(mediaCursor.isAfterLast()){ 
            Toast.makeText(getApplicationContext(),"End of Line",Toast.LENGTH_SHORT).show();
        }
        else{
                String path=mediaCursor.getString(dataIdx);
                Toast.makeText(getApplicationContext(),"playing: "+path, Toast.LENGTH_SHORT).show();
                videoView.setVideoPath(path);
                videoView.start();
        }
}



@Override
public void onDestroy(){
     if (mediaCursor!=null){
         mediaCursor.close();
     }
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
}



 01-29 10:43:39.186: W/WindowManager(161): Failure taking screenshot for (246x410) to layer 21015
 01-29 10:43:39.256: I/Choreographer(429): Skipped 32 frames!  The application may be doing too much work on its main thread.
 01-29 10:43:39.535: I/Choreographer(429): Skipped 59 frames!  The application may be doing too much work on its main thread.
 01-29 10:44:03.995: D/AndroidRuntime(1345): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
 01-29 10:44:03.995: D/AndroidRuntime(1345): CheckJNI is ON
 01-29 10:44:04.035: D/dalvikvm(1345): Trying to load lib libjavacore.so 0x0
 01-29 10:44:04.045: D/dalvikvm(1345): Added shared lib libjavacore.so 0x0
 01-29 10:44:04.075: D/dalvikvm(1345): Trying to load lib libnativehelper.so 0x0
 01-29 10:44:04.075: D/dalvikvm(1345): Added shared lib libnativehelper.so 0x0
 01-29 10:44:04.895: D/AndroidRuntime(1345): Calling main entry com.android.commands.pm.Pm
 01-29 10:44:04.965: W/ActivityManager(161): No content provider found for permission revoke: file:///data/local/tmp/VideoTEST.apk
 01-29 10:44:04.985: W/ActivityManager(161): No content provider found for permission revoke: file:///data/local/tmp/VideoTEST.apk
 01-29 10:44:05.266: D/dalvikvm(161): GC_CONCURRENT freed 550K, 45% free 10453K/18887K, paused 19ms+27ms, total 148ms
 01-29 10:44:05.326: I/PackageManager(161): Removing non-system package:com.example.videotest
 01-29 10:44:05.326: I/ActivityManager(161): Force stopping package com.example.videotest uid=10044
 01-29 10:44:05.326: I/ActivityManager(161): Killing proc 1282:com.example.videotest/u0a44: force stop
 01-29 10:44:05.326: W/ActivityManager(161): Force removing ActivityRecord{416c3d88 com.example.videotest/.MainActivity}: app died, no saved state
 01-29 10:44:05.376: W/InputDispatcher(161): channel '416195c8 com.example.videotest/com.example.videotest.MainActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
 01-29 10:44:05.376: E/InputDispatcher(161): channel '416195c8 com.example.videotest/com.example.videotest.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
 01-29 10:44:05.386: I/WindowState(161): WIN DEATH: Window{416195c8 com.example.videotest/com.example.videotest.MainActivity paused=false}
 01-29 10:44:05.386: W/InputDispatcher(161): Attempted to unregister already unregistered input channel '416195c8 com.example.videotest/com.example.videotest.MainActivity (server)'
 01-29 10:44:05.386: W/WindowManager(161): Force-removing child win Window{4167b698 SurfaceView paused=false} from container Window{416195c8 com.example.videotest/com.example.videotest.MainActivity paused=false}
 01-29 10:44:05.426: W/WindowManager(161): Failed looking up window
 01-29 10:44:05.426: W/WindowManager(161): java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@4161c220 does not exist
 01-29 10:44:05.426: W/WindowManager(161):  at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:7640)
   01-29 10:44:05.426: W/WindowManager(161):    at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:7631)
   01-29 10:44:05.426: W/WindowManager(161):    at com.android.server.wm.WindowState$DeathRecipient.binderDied(WindowState.java:854)
  01-29 10:44:05.426: W/WindowManager(161):     at android.os.BinderProxy.sendDeathNotice(Binder.java:449)
  01-29 10:44:05.426: W/WindowManager(161):     at dalvik.system.NativeStart.run(Native Method)
  01-29 10:44:05.426: I/WindowState(161): WIN DEATH: null
  01-29 10:44:05.426: I/WindowManager(161): WINDOW DIED Window{416195c8 co m.example.videotest/com.example.videotest.MainActivity paused=false}
  01-29 10:44:05.666: W/InputMethodManagerService(161): Got RemoteException sending setActive(false) notification to pid 1282 uid 10044
   01-29 10:44:06.095: I/PackageManager(161): Package com.example.videotest codePath changed from /data/app/com.example.videotest-1.apk to /data/app/com.example.videotest-2.apk; Retaining data and using new
     01-29 10:44:06.095: I/PackageManager(161): Running dexopt on: com.example.videotest
     01-29 10:44:06.965: D/dalvikvm(1356): DexOpt: load 131ms, verify+opt 486ms, 745428 bytes
    01-29 10:44:06.986: I/ActivityManager(161): Force stopping package com.example.videotest uid=10044
  01-29 10:44:06.995: W/PackageManager(161): Code path for pkg : com.example.videotest changing from /data/app/com.example.videotest-1.apk to /data/app/com.example.videotest-2.apk
  01-29 10:44:06.995: W/PackageManager(161): Resource path for pkg : com.example.videotest changing from /data/app/com.example.videotest-1.apk to /data/app/com.example.videotest-2.apk
  01-29 10:44:07.115: D/PackageManager(161): New package installed in /data/app/com.example.videotest-2.apk
  01-29 10:44:07.236: I/ActivityManager(161): Force stopping package com.example.videotest uid=10044
  01-29 10:44:07.246: D/dalvikvm(429): WAIT_FOR_CONCURRENT_GC blocked 0ms
  01-29 10:44:07.286: D/dalvikvm(616): WAIT_FOR_CONCURRENT_GC blocked 0ms
  01-29 10:44:07.436: D/dalvikvm(429): GC_EXPLICIT freed 10435K, 60% free 8931K/21831K, paused 11ms+23ms, total 186ms
  01-29 10:44:07.446: D/dalvikvm(540): WAIT_FOR_CONCURRENT_GC blocked 0ms
  01-29 10:44:07.466: D/dalvikvm(616): GC_EXPLICIT freed 4569K, 37% free 10401K/16455K, paused 7ms+33ms, total 179ms
  01-29 10:44:07.666: I/InputReader(161): Reconfiguring input devices.  changes=0x00000010
  01-29 10:44:07.676: D/PackageManager(161): generateServicesMap(android.accounts.AccountAuthenticator): 2 services unchanged
   01-29 10:44:07.686: D/dalvikvm(540): GC_EXPLICIT freed 86K, 7% free 8394K/8967K, paused 12ms+8ms, total 218ms
   01-29 10:44:07.745: I/AccountTypeManager(710): Loaded meta-data for 1 account types, 0 accounts in 63ms(wall) 6ms(cpu)
   01-29 10:44:07.745: D/PackageManager(161): generateServicesMap(android.content.SyncAdapter): 4 services unchanged
   01-29 10:44:07.755: D/BackupManagerService(161): Received broadcast Intent { act=android.intent.action.PACKAGE_REMOVED dat=package:com.example.videotest flg=0x8000010 (has extras) }
   01-29 10:44:07.865: D/dalvikvm(161): GC_CONCURRENT freed 564K, 45% free 10429K/18887K, paused 53ms+13ms, total 188ms
   01-29 10:44:07.865: D/dalvikvm(161): WAIT_FOR_CONCURRENT_GC blocked 109ms
   01-29 10:44:08.035: D/dalvikvm(161): GC_EXPLICIT freed 61K, 46% free 10369K/18887K, paused 13ms+29ms, total 166ms
   01-29 10:44:08.135: I/ActivityManager(161): Start proc com.android.keychain for broadcast com.android.keychain/.KeyChainBroadcastReceiver: pid=1357 uid=1000 gids={1015, 3002, 3001, 3003, 1028}
     01-29 10:44:08.226: D/PackageManager(161): generateServicesMap(android.accounts.AccountAuthenticator): 2 services unchanged
     01-29 10:44:08.256: D/PackageManager(161): generateServicesMap(android.content.SyncAdapter): 4 services unchanged
     01-29 10:44:08.285: I/InputReader(161): Reconfiguring input devices.  changes=0x00000010
   01-29 10:44:08.296: D/BackupManagerService(161): Received broadcast Intent { act=android.intent.action.PACKAGE_ADDED dat=package:com.example.videotest flg=0x8000010 (has extras) }
     01-29 10:44:08.296: V/BackupManagerService(161): removePackageParticipantsLocked: uid=10044 #1
      01-29 10:44:08.515: V/BackupManagerService(161): addPackageParticipantsLocked: #1
     01-29 10:44:08.556: W/InputMethodManagerService(161): Found no subtypes in a system IME: com.android.inputmethod.pinyin
      01-29 10:44:08.586: E/Trace(1357): error opening trace file: No such file or directory (2)
   01-29 10:44:08.686: I/AccountTypeManager(710): Loaded meta-data for 1 account types, 0 accounts in 9ms(wall) 5ms(cpu)
    01-29 10:44:08.796: D/dalvikvm(161): WAIT_FOR_CONCURRENT_GC blocked 0ms
      01-29 10:44:08.975: W/RecognitionManagerService(161): no available voice recognition services found
    01-29 10:44:09.146: D/dalvikvm(161): GC_EXPLICIT freed 367K, 45% free 10413K/18887K, paused 57ms+22ms, total 355ms
  01-29 10:44:09.186: D/AndroidRuntime(1345): Shutting down VM
  01-29 10:44:09.196: D/dalvikvm(1345): GC_CONCURRENT freed 101K, 78% free 458K/2048K, paused 1ms+2ms, total 12ms
       01-29 10:44:09.206: D/jdwp(1345): Got wake-up signal, bailing out of select
      01-29 10:44:09.206: D/dalvikvm(1345): Debugger has detached; object registry had 1 entries
     01-29 10:44:09.206: I/AndroidRuntime(1345): NOTE: attach of thread 'Binder_3' failed
      01-29 10:44:10.085: D/AndroidRuntime(1377): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
      01-29 10:44:10.085: D/AndroidRuntime(1377): CheckJNI is ON
     01-29 10:44:10.176: D/dalvikvm(1377): Trying to load lib libjavacore.so 0x0
     01-29 10:44:10.186: D/dalvikvm(1377): Added shared lib libjavacore.so 0x0
     01-29 10:44:10.246: D/dalvikvm(1377): Trying to load lib libnativehelper.so 0x0
     01-29 10:44:10.246: D/dalvikvm(1377): Added shared lib libnativehelper.so 0x0
    01-29 10:44:11.126: D/AndroidRuntime(1377): Calling main entry com.an droid.commands.am.Am
     01-29 10:44:11.156: I/ActivityManager(161): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.videotest/.MainActivity u=0} from pid 1377
     01-29 10:44:11.186: W/WindowManager(161): Failure taking screenshot for (246x410) to    layer 21005
     01-29 10:44:11.226: D/AndroidRuntime(1377): Shutting down VM
     01-29 10:44:11.246: I/AndroidRuntime(1377): NOTE: attach of thread 'Binder_3' failed
     01-29 10:44:11.246: D/dalvikvm(1377): GC_CONCURRENT freed 102K, 77% free 489K/2048K, paused 11ms+1ms, total 23ms
    01-29 10:44:11.256: D/jdwp(1377): Got wake-up signal, bailing out of select
     01-29 10:44:11.256: D/dalvikvm(1377): Debugger has detached; object registry had 1 entries
      01-29 10:44:11.266: D/dalvikvm(1388): Not late-enabling CheckJNI (already on)
     01-29 10:44:11.286: I/ActivityManager(161): Start proc com.example.videotest for activity com.example.videotest/.MainActivity: pid=1388 uid=10044 gids={1015, 1028}
     01-29 10:44:11.705: E/Trace(1388): error opening trace file: No such file or directory (2)
     01-29 10:44:12.256: D/dalvikvm(161): WAIT_FOR_CONCURRENT_GC blocked 0ms
     01-29 10:44:12.406: D/dalvikvm(161): GC_EXPLICIT freed 110K, 45% free 10473K/18887K, paused 10ms+12ms, total 157ms
     01-29 10:44:12.606: I/Choreographer(1388): Skipped 38 frames!  The application may be doing too much work on its main thread.
     01-29 10:44:12.685: D/gralloc_goldfish(1388): Emulator without GPU emulation detected.
     01-29 10:44:12.755: I/ActivityManager(161): Displayed com.example.videotest/.MainActivity: +1s541ms
     01-29 10:44:13.146: I/Choreographer(1388): Skipped 92 frames!  The application may be doing too much work on its main thread.
     01-29 10:48:55.096: E/ThrottleService(161): problem during onPollAlarm: java.lang.IllegalStateException: problem parsing stats: java.io.FileNotFoundException: /proc/net/xt_qtaguid/iface_stat_all: open failed: ENOENT (No such file or directory)
      01-29 10:50:28.105: D/dalvikvm(457): GC_CONCURRENT freed 403K, 7% free 8578K/9159K, paused 17ms+4ms, total 57ms
4

1 回答 1

2

在你的onCreate()方法中

这条线

    VideoView videoView=(VideoView) findViewById(R.id.videoView1);

应该

    videoView=(VideoView) findViewById(R.id.videoView1);
于 2013-01-29T03:36:30.323 回答