简体   繁体   English

VideoView没有响应,Eclipse Android

[英]VideoView its not responding, Eclipse Android

Im programing an app, that have 4 videos on it, when i play the first video all is ok, but when i try to play the second video, its say that the application has stopped unexpectedly, and im using the some code in the 2 activitys. 我正在编写一个有4个视频的应用程序,当我播放第一个视频时一切正常,但是当我尝试播放第二个视频时,它说该应用程序已意外停止,我在2个视频中使用了一些代码活动。 i dont find any error, is my first program, thank you very much in advance i put the codes bellow: 我没有发现任何错误,这是我的第一个程序,非常感谢您我将代码放在下面:

Layout Xml : primeraventana.xml 布局Xml:primaryaventana.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView
 android:id="@+id/textview1"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="@string/Escala_Uno" />

<VideoView
 android:id="@+id/videoView1"
 android:layout_width="match_parent"
 android:layout_height="254dp" />

<Button
 android:id="@+id/boton3"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="@string/Menú_Principal" />

</LinearLayout>

Java Class : primeraventana.java Java类:primaryaventana.java

package gabrielrojas.com;



import android.os.Bundle;
import android.app.Activity;


import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.TextView; 
import android.widget.VideoView;
import android.net.Uri;

public class primeraventana extends Activity  {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.primeraventana);

VideoView mVideoView = (VideoView) findViewById(R.id.videoView1);
mVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() 
+"/"+R.raw.test));
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();  
mVideoView.start();     
mVideoView.isPlaying();  
mVideoView.stopPlayback();  
mVideoView.clearFocus();

TextView text = (TextView) findViewById(R.id.textview1);
Button boton3 = (Button) findViewById(R.id.boton3);

text.setText(R.string.Escala_Uno);

boton3.setText(R.string.Menú_Principal);


boton3.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
          finish();

}}); }}

Layout Xml :: segundaventana.xml 布局Xml :: segundaventana.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TextView 
android:id="@+id/textview2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Escala_Dos"/>

 <VideoView
 android:id="@+id/videoView2"
 android:layout_width="match_parent"
 android:layout_height="254dp" />

 <Button 
 android:id="@+id/boton4"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:text="@string/Menú_Principal"/>


 </LinearLayout>

Java Class :: segundaventana.java Java类:: segundaventana.java

package gabrielrojas.com;



import android.os.Bundle;
import android.app.Activity;


import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.TextView; 
import android.widget.VideoView;
import android.net.Uri;

public class segundaventana extends Activity  {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.primeraventana);

VideoView mVideoView = (VideoView) findViewById(R.id.videoView2);
mVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() 
+"/"+R.raw.test));
mVideoView.setMediaController(new MediaController(this));
mVideoView.requestFocus();  
mVideoView.start();     
mVideoView.isPlaying();  
mVideoView.stopPlayback();  
mVideoView.clearFocus();

TextView text = (TextView) findViewById(R.id.textview2);
Button boton4 = (Button) findViewById(R.id.boton4);

text.setText(R.string.Escala_Dos);

boton4.setText(R.string.Menú_Principal);


boton4.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
          finish();

}}); }}

AndroidManifest Android清单

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="gabrielrojas.com"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="7"
    android:targetSdkVersion="15" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".PruebaNumero3"
        android:label="@string/title_activity_prueba_numero3" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".primeraventana"/>
    <activity android:name=".segundaventana" />
    <activity android:name=".terceraventana" />
    <activity android:name=".cuartaventana" />
    <activity android:name=".VideoActivity"
              android:label="@string/app_name"
              android:screenOrientation="landscape"
              android:theme="@android:style/Theme.NoTitleBar"
              android:noHistory="true"/>
</application>

</manifest>

Your problem lies here: 您的问题出在这里:

Setting the layout:



public class segundaventana extends Activity  {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.primeraventana);-------------------------> Here lies your problem

Change to: 改成:

public class segundaventana extends Activity  {

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.segundaventana);---------------------->this layout contains your videoview2

Try it and say.. 试试吧,说..

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

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