3

我有以下简单的 Android 应用程序。

package com.example.videotest;

public class MainActivity extends Activity {

private Button playButton;
private Button clearButton;
private Button stopButton;
private Button defaultButton;
private VideoView mVideoView;
private EditText editText;
private String videoAddress;
private static final String TAG = "videoTest"; 
private String keyValue = "videoAddress";
private String defaultAddress = "rtsp://v6.cache7.c.youtube.com/CjYLENy73wIaLQlpqssvHCj9nxMYDSANFEIJbXYtZ29vZ2xlSARSBXdhdGNoYLXw9ZeX2OLcUAw=/0/0/0/video.3gp";


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    SharedPreferences prefs = this.getSharedPreferences(TAG, 0);

    videoAddress = prefs.getString(keyValue, defaultAddress);

    playButton = (Button)findViewById(R.id.button1);
    clearButton = (Button)findViewById(R.id.button2);
    stopButton = (Button)findViewById(R.id.button3);
    defaultButton = (Button)findViewById(R.id.button4);

    mVideoView = (VideoView) findViewById(R.id.videoView1);
    editText = (EditText)findViewById(R.id.editText1);
    editText.setText(videoAddress);

    defaultButton.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {

             editText.setText(defaultAddress);
             SharedPreferences appSettings =  getSharedPreferences(TAG, 0);
             SharedPreferences.Editor prefEditor = appSettings.edit();          
             prefEditor.putString(keyValue, defaultAddress);    
             prefEditor.commit();


        }
    });

    stopButton.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {

             mVideoView.stopPlayback();


        }
    });

    playButton.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {


            videoAddress = editText.getText().toString();
             SharedPreferences appSettings =  getSharedPreferences(TAG, 0);
             SharedPreferences.Editor prefEditor = appSettings.edit();          
             prefEditor.putString(keyValue, videoAddress);  
             prefEditor.commit();
             //PlayRtspStream("rtsp://10.0.0.32:5004/aac5.sdp");
             PlayRtspStream(videoAddress);


        }
    });

    clearButton.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {

             editText.setText("");
             SharedPreferences appSettings =  getSharedPreferences(TAG, 0);
             SharedPreferences.Editor prefEditor = appSettings.edit();          
             prefEditor.putString(keyValue, "");    
             prefEditor.commit();


        }
    });


}

private void PlayRtspStream(String rtspUrl){  
    mVideoView.setVideoPath(rtspUrl);
    //mVideoView.setVideoURI(Uri.parse(rtspUrl));  
    mVideoView.requestFocus();  
    mVideoView.start();  
}  

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
}

AndroidManifest.xml 文件

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.videotest"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="8" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.videotest.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

当我运行应用程序并将视频视图的视频路径设置为默认地址时,我收到提示“无法播放视频”。这是 logcat 文件。

03-07 21:09:51.305: D/MediaPlayer(20031): Couldn't open file on client side, trying server side
03-07 21:09:51.305: E/MediaPlayer(20031): Unable to to create media player
03-07 21:09:51.305: W/VideoView(20031): Unable to open content: rtsp://v6.cache7.c.youtube.com/CjYLENy73wIaLQlpqssvHCj9nxMYDSANFEIJbXYtZ29vZ2xlSARSBXdhdGNoYLXw9ZeX2OLcUAw=/0/0/0/video.3gp
03-07 21:09:51.305: W/VideoView(20031): java.io.IOException: setDataSource failed.: status=0x80000000
03-07 21:09:51.305: W/VideoView(20031):     at android.media.MediaPlayer._setDataSource(Native Method)
03-07 21:09:51.305: W/VideoView(20031):     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:958)
03-07 21:09:51.305: W/VideoView(20031):     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:946)
03-07 21:09:51.305: W/VideoView(20031):     at android.media.MediaPlayer.setDataSource(MediaPlayer.java:899)
03-07 21:09:51.305: W/VideoView(20031):     at android.widget.VideoView.openVideo(VideoView.java:236)
03-07 21:09:51.305: W/VideoView(20031):     at android.widget.VideoView.setVideoURI(VideoView.java:198)
03-07 21:09:51.305: W/VideoView(20031):     at android.widget.VideoView.setVideoURI(VideoView.java:188)
03-07 21:09:51.305: W/VideoView(20031):     at android.widget.VideoView.setVideoPath(VideoView.java:184)
03-07 21:09:51.305: W/VideoView(20031):     at com.example.videotest.MainActivity.PlayRtspStream(MainActivity.java:109)
03-07 21:09:51.305: W/VideoView(20031):     at com.example.videotest.MainActivity.access$6(MainActivity.java:108)
03-07 21:09:51.305: W/VideoView(20031):     at com.example.videotest.MainActivity$3.onClick(MainActivity.java:85)
03-07 21:09:51.305: W/VideoView(20031):     at android.view.View.performClick(View.java:4204)
03-07 21:09:51.305: W/VideoView(20031):     at android.view.View$PerformClick.run(View.java:17355)
03-07 21:09:51.305: W/VideoView(20031):     at android.os.Handler.handleCallback(Handler.java:725)
03-07 21:09:51.305: W/VideoView(20031):     at android.os.Handler.dispatchMessage(Handler.java:92)
03-07 21:09:51.305: W/VideoView(20031):     at android.os.Looper.loop(Looper.java:137)
03-07 21:09:51.305: W/VideoView(20031):     at android.app.ActivityThread.main(ActivityThread.java:5041)
03-07 21:09:51.305: W/VideoView(20031):     at java.lang.reflect.Method.invokeNative(Native Method)
03-07 21:09:51.305: W/VideoView(20031):     at java.lang.reflect.Method.invoke(Method.java:511)
03-07 21:09:51.305: W/VideoView(20031):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-07 21:09:51.305: W/VideoView(20031):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-07 21:09:51.305: W/VideoView(20031):     at dalvik.system.NativeStart.main(Native Method)
03-07 21:09:51.315: D/VideoView(20031): Error: 1,0

关于我做错了什么的任何想法?

4

1 回答 1

3

由Praful解决,在Manifest.xml中添加Internet权限

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

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.videotest"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="8" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.videotest.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
于 2013-12-10T17:22:10.953 回答