【问题标题】:java.lang.StringIndexOutOfBoundsException while playing video in videoView : Android v 4.2.1在 videoView 中播放视频时出现 java.lang.StringIndexOutOfBoundsException:Android v 4.2.1
【发布时间】:2013-09-22 19:20:42
【问题描述】:

当我在 Android 版本 4.2.1 的 videoView 上播放视频时,我遇到了这个崩溃。我专门在 Micromax Canvas A210 设备上发现了这一点。它没有显示发生错误的任何消息。这是应用程序中的错误还是错误?崩溃日志如下:

09-18 11:05:53.245: E/AndroidRuntime(2323): FATAL EXCEPTION: main
09-18 11:05:53.245: E/AndroidRuntime(2323): java.lang.StringIndexOutOfBoundsException: length=11; regionStart=0; regionLength=-1
09-18 11:05:53.245: E/AndroidRuntime(2323):     at java.lang.String.startEndAndLength(String.java:583)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at java.lang.String.substring(String.java:1464)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.widget.VideoView.openVideo(VideoView.java:407)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.widget.VideoView$6.surfaceCreated(VideoView.java:730)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.view.SurfaceView.updateWindow(SurfaceView.java:606)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.view.SurfaceView.access$000(SurfaceView.java:88)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.view.SurfaceView$3.onPreDraw(SurfaceView.java:183)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:692)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2123)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1139)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4879)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.view.Choreographer.doCallbacks(Choreographer.java:579)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.view.Choreographer.doFrame(Choreographer.java:548)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.os.Handler.handleCallback(Handler.java:725)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.os.Handler.dispatchMessage(Handler.java:92)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.os.Looper.loop(Looper.java:153)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at android.app.ActivityThread.main(ActivityThread.java:5297)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at java.lang.reflect.Method.invokeNative(Native Method)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at java.lang.reflect.Method.invoke(Method.java:511)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
09-18 11:05:53.245: E/AndroidRuntime(2323):     at dalvik.system.NativeStart.main(Native Method)

我已经测试过我的应用并且运行良好的其他版本和设备是:

Android versions: 4.1.2, 4.2.2, 4.3, 2.3.3, 4.0.3, 4.0.4
Devices: Samsung Galaxy s2, Samsung Galaxy Tab 2 (7" and 10"), Samsung Galaxy s plus, Sony Xperia Tipo dual, Samsung Galaxy Grand (Quatro and Mega), Nexus 4

【问题讨论】:

  • 看起来 AOSP 版本的 VideoView.openVideo() 没有任何对 String.substring() 的调用,所以它一定是供应商特定的错误。在不知道他们更改了什么导致错误的情况下,您不可能采取任何措施来解决该问题。
  • 是的,对于特定于供应商的问题,我也有同样的感觉,因为我在 Play Store 上的应用程序中收到了完全相同的设备 (Micromax Canvas A210) 的相同崩溃日志。供应商是否允许更改这些类并且 Google 对此无能为力?
  • 有一套测试 (CTS) 可确保 API 全部按文档说明工作,但它无法进行全面的故障测试。如果供应商决定对 substring() 进行不安全的调用,该调用在某些输入上崩溃但通过了 CTS,那就是他们的调用。您可能需要联系 Micromax 以让他们了解该问题。
  • 好的,如果有问题我会在Micromax官方论坛发帖。谢谢你的解释。
  • 这个崩溃的任何解决方案??

标签: android android-4.2-jelly-bean android-videoview


【解决方案1】:

您是开发人员并在您的应用程序中使用视频视图。如果是这样,请尝试调试并验证您是否向视频视图提供了有效的 uri/url。虽然在 android.widget.VideoView 类的 openVideo() 中有一个空检查,但 uri 可能是空字符串。

Here is the source of the Video View class for the android version you mentioned.

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,发现这是使用 videoview 时特定于 micromax 的错误。 这是在 android 中使用“TextureView”的另一种方法

    BackGroundVideo.java

    public class BackGroundVideo extends AppCompatActivity implements TextureView.SurfaceTextureListener {
    ProfileTracker profileTracker;
    private MediaPlayer mMediaPlayer;
    private TextureView mTextureView;
    private static final String TAG = sus.class.getName();
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_layout);
    
        initView();
    
    }
    
    private void initView() {
        mTextureView = (TextureView) findViewById(R.id.play_video_texture);
        // SurfaceTexture is available only after the TextureView
        // is attached to a window and onAttachedToWindow() has been invoked.
        // We need to use SurfaceTextureListener to be notified when the SurfaceTexture
        // becomes available.
        mTextureView.setSurfaceTextureListener(this);
    }
    
    
    
    
    
    
    
    @Override
    public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) {
        Surface surface = new Surface(surfaceTexture);
    
    
            mMediaPlayer.prepareAsync();
    
            // Play video when the media source is ready for playback.
            mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                @Override
                public void onPrepared(MediaPlayer mediaPlayer) {
                    mediaPlayer.start();
                }
            });
    
        } catch (IllegalArgumentException e) {
            Log.d(TAG, e.getMessage());
        } catch (SecurityException e) {
            Log.d(TAG, e.getMessage());
        } catch (IllegalStateException e) {
            Log.d(TAG, e.getMessage());
        } catch (IOException e) {
            Log.d(TAG, e.getMessage());
        }
    
    }
    
    @Override
    public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
    
    }
    
    @Override
    public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
        return false;
    }
    
    @Override
    public void onSurfaceTextureUpdated(SurfaceTexture surface) {
    
    }
    

    }

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.android.test.sus">
    <TextureView
        android:id="@+id/play_video_texture"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:keepScreenOn="true"
        android:fitsSystemWindows="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentBottom="true"/>
    
    
    
    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button2"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="167dp" />
    
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="Small Text"
        android:id="@+id/te"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="122dp" />
    </RelativeLayout>
    

    splash_layout.xml

    希望这对你有用!

    【讨论】:

      猜你喜欢
      • 2012-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-18
      相关资源
      最近更新 更多