2016-07-08 2 views
0

내 안드로이드 응용 프로그램에서 MP4를 재생하려고하는데 어떤 이유로 작동하지 않습니다.안드로이드 응용 프로그램에서 비디오를 재생하는 중 오류가 발생했습니다.

I가 안드로이드에 대한 모든 형식 및 파일 containters을 보았다

:이 비디오를 작동하게하는 데 사용할 수있는 온라인 또는 오프라인 컨버터가 있는가 https://developer.android.com/guide/appendix/media-formats.html

?

내 홈페이지 :

public class MainActivity extends AppCompatActivity { 

LinearLayout screen; 
Handler handler; 
int fadeTime; 
Button BtnTextColor; 
Random rnd = new Random(); 
Button BackgroundButton; 
final Context context = this; 
private Button button; 
private EditText result; 
Button ChangeName; 


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




      VideoView mediaPlayer = (VideoView)findViewById(R.id.videoView1); 
      String uriPath2 = "android.resource://com.example.toyo.playvideo/"+R.raw.video; 
      Uri uri2 = Uri.parse(uriPath2); 
      mediaPlayer.setVideoURI(uri2); 
      mediaPlayer.requestFocus(); 
      mediaPlayer.start(); 

fadeTime = -20; //text fade timer 

    android.support.v7.app.ActionBar theactionbar = getSupportActionBar(); //ActionBar 
    screen = (LinearLayout) findViewById(R.id.screen); //Background Screen 


    //hide action bar (top) 
    theactionbar.hide(); 


    //fades from white to blue 

    ObjectAnimator colorFade = ObjectAnimator.ofObject(screen, "backgroundColor", new ArgbEvaluator(), Color.argb(0, 0, 0, 0), 0xff7F87CF); 
    colorFade.setDuration(3000); 
    colorFade.start(); 

    //fade text 

    Animation animFadeIn; 
    animFadeIn = AnimationUtils.loadAnimation(this, R.anim.text_fade); 
    animFadeIn.start(); 
    animFadeIn = new AlphaAnimation(0.0f, 1.0f); 
    animFadeIn.setDuration(8000); 
    animFadeIn.start(); 


    DelayedDialog(); 


    // Button Listeners 
    BackgroundButton = (Button) findViewById(R.id.Change_Background); 
    ChangeName = (Button) findViewById(R.id.ChangeWelcome); 


    ChangeName.setOnClickListener(new View.OnClickListener() { 
     //Enter Name 
     @Override 
     public void onClick(View v) { 

     Dialog(); 

       } 
      }); 


} 

public void onRadioButtonClicked(View view) { 

    // R. Button checked 
    final boolean checked = ((RadioButton) view).isChecked(); 


    // Which R. Button was checked 
    switch (view.getId()) { 
     //Rapid R.Button selected 
     case R.id.BackgroundRapidChange: 
      if (checked) { 

       BackgroundButton.setOnClickListener(new View.OnClickListener() { 
        //Rapid Background Switch 


        @Override 
        public void onClick(View v) { 

         RapidBackgroundColor(); 

         BtnTextColor = (Button) findViewById(R.id.Change_Text); 
         final TextView tt = (TextView) findViewById(R.id.Welcome_Text); 

         //Rapid Text Switch 
         BtnTextColor.setOnClickListener(new View.OnClickListener() { 
          @Override 
          public void onClick(View v) { 
           RapidTextColor(); 

          } 
         }); 
        } 
       }); 

       if(checked == false) { 
       Dialog(); 
       } 
      } 



      break; 

     //Slow R. Button selected 
     case R.id.BackgroundSlowChange: 
      if (checked) { 

       //Slow Background Switch 
       BackgroundButton.setOnClickListener(new View.OnClickListener() { 
        public void onClick(View v) { 

         SlowBackgroundChangeColor(); 


         BtnTextColor = (Button) findViewById(R.id.Change_Text); 

         //Slow Text Switch 
         BtnTextColor.setOnClickListener(new View.OnClickListener() { 
          @Override 
          public void onClick(View v) { 

           SlowTextColor(); 
          } 
         }); 
        } 
       }); 


      } 

      break; 
    } 


} 


public void SlowBackgroundChangeColor() { 

    int Changecolor = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)); 
    ObjectAnimator ChangecolorFade = ObjectAnimator.ofObject(screen, "backgroundColor", new ArgbEvaluator(), 
      Color.argb(Changecolor, Changecolor, Changecolor, Changecolor), Changecolor); 


    //slow change 
    ChangecolorFade.setDuration(2000); 
    ChangecolorFade.start(); 

} 

public void SlowTextColor() { 
    final TextView tt = (TextView) findViewById(R.id.Welcome_Text); 
    int Changecolor = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)); 
    int ChangecolorText = Color.argb(225, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)); 


    ValueAnimator colorAnim = ObjectAnimator.ofInt(tt, "textColor", ChangecolorText, Changecolor); 
    colorAnim.setDuration(2000); 
    colorAnim.setEvaluator(new ArgbEvaluator()); 

} 

public void RapidTextColor() { 
    final TextView tt = (TextView) findViewById(R.id.Welcome_Text); 
    Random rnd = new Random(); 
    int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)); 
    tt.setTextColor(color); 
} 

public void RapidBackgroundColor() { 
    int Changecolor = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)); 
    ObjectAnimator ChangecolorFade = ObjectAnimator.ofObject(screen, "backgroundColor", new ArgbEvaluator(), 
      Color.argb(Changecolor, Changecolor, Changecolor, Changecolor), Changecolor); 

    //fast change 
    screen.setBackgroundColor(Changecolor); 

} 
public void Dialog(){ 
button = (Button) findViewById(R.id.buttonPrompt); 
result = (EditText) findViewById(R.id.editTextResult); 

LayoutInflater li = LayoutInflater.from(context); 
View promptsView = li.inflate(R.layout.dialog, null); 

final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
     context); 

final AlertDialog.Builder noText = new AlertDialog.Builder(
     context); 

alertDialogBuilder.setView(promptsView); 

final EditText userInput = (EditText) promptsView 
     .findViewById(R.id.editTextDialogUserInput); 

alertDialogBuilder 
     .setCancelable(false) 
     .setPositiveButton("OK", 
       new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog,int id) { 

          if(userInput.getText().length() ==0){ 
           Dialog(); 
          } 

         TextView ChangeWelcomeText = (TextView) findViewById(R.id.Welcome_Text); 
           ChangeWelcomeText.setText("Welcome \n" + userInput.getText()); 
        } 
       }); 

AlertDialog alertDialog = alertDialogBuilder.create(); 
alertDialog.show(); 
} 

public void DelayedDialog() { 
    Handler handler = new Handler(); 
    handler.postDelayed(new Runnable() { 
     @Override 
     public void run() { 
      Dialog(); 

     } 
    }, 4000); 
} 
} 

그리고 이것은 내 레이아웃 XML입니다 :

<RadioGroup android:id="@+id/backgroundoption" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <RadioButton android:id="@+id/BackgroundRapidChange" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="onRadioButtonClicked" 
     android:text="Rapid" /> 

    <RadioButton android:id="@+id/BackgroundSlowChange" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="onRadioButtonClicked" 
     android:text="Slow" /> 

</RadioGroup> 

<RadioGroup 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <RadioButton android:id="@+id/Auto" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="onRadioButtonClicked" 
     android:text="Auto" /> 

    <RadioButton android:id="@+id/Manual" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="onRadioButtonClicked" 
     android:text="Manual" /> 
</RadioGroup> 




<Button android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:text="Change Background" 
    android:id="@+id/Change_Background" 
    android:layout_centerHorizontal="true" 
    android:gravity="center|bottom" 
    android:layout_gravity="center_horizontal|center" 
    > 
</Button> 

<Button android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:text="Change Text" 
    android:id="@+id/Change_Text" 
    android:layout_centerHorizontal="true" 
    android:gravity="center|bottom" 
    android:layout_gravity="center_horizontal|center" 
    > 
</Button> 

<Button 
    android:id="@+id/ChangeWelcome" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Change Name" 
    > 

</Button> 


<TextView 
    android:id="@+id/Welcome_Text" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:textSize="80dp" 
    android:text="Welcome" 
    android:textColor="@color/white" 
    android:gravity="center_horizontal" 
    > 


</TextView> 
<Button 
    android:id="@+id/buttonPrompt" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Please Enter your Name" /> 

<EditText 
    android:id="@+id/editTextResult" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

</EditText> 


<VideoView 
    android:id="@+id/videoView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerVertical="true" 
    android:layout_centerHorizontal="true" /> 

그것은 조금 길고 아주 지저분한, 그것은 내 첫 안드로이드 앱

입니다
+0

"결코 놀지 않을 것입니다"라는게 무슨 뜻이야? logcat의 모든 오류 메시지? 22 : –

+0

내가지고있어 오류가 '07-09 04 12.590 12805-12805/geepool.myfirstandroidapp의 E/MediaPlayer를 : 자막 컨트롤러가 있어야 이미 – deathsonic

+0

을 set' 내가 사용하고있는 코드는 다음과 같습니다 ' VideoView mVideoView2 = (VideoView) findViewById (R.id.videoView1); String uriPath2 = "android.resource : //com.example.toyo.playvideo/"+ R.raw.video; Uri uri2 = Uri.parse (uriPath2); mVideoView2.setVideoURI (uri2); mVideoView2.requestFocus(); mVideoView2.start(); ' – deathsonic

답변

0

글쎄, 내가 그럭저럭 나에게 알아 차릴 수 있었던 것에서 다음 l 이 문제를 일으켰습니다.

String uriPath2 = "android.resource://com.example.toyo.playvideo/"+R.raw.video; 

는 R 파일은 주로 라인은 다음과 같이 읽은 이들 자원

에 안드로이드 시스템에 의해 주어진 IDS/숫자 번역의 일종이다 안드로이드 자원에 대한 인간이 읽을 수있는 값을 제공합니다;

android.resource : 당신에 의해 내부 자원에서 파일을 읽을 수 있습니다 숫자가 아닌 URL에 동영상 파일 이름을 연결 //com.example.toyo.playvideo/2131427330

, 이외의 R.raw.fileName 또는 온라인 URL을 사용하십시오.

다른 주;

<VideoView 
     android:id="@+id/videoView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true" /> 

대신 다음을 사용하십시오.

<VideoView 
    android:id="@+id/videoView1" 
    android:layout_width="match_parent" 
    android:minHeight="100dp" 
    android:minWidth="50dp" 
    android:layout_height="wrap_content" 
    android:layout_centerVertical="true" 
    android:layout_centerHorizontal="true" /> 

비디오로드 조금 걸릴 크기가 크며 경우 작동 또는 있지 않다면 당신은 혼란 얻을 수 있습니다 그것은

를로드하는 데 시간이 너무 오래 걸렸다으로 비디오 컨테이너를 고정 너비/높이 또는 최소 너비/높이를 줄

행운을 빈다, 내 대답이 도움이 되었기를 바랍니다.

+0

D : 가장 효과적 이었지만 새로운 것을 배웠습니다 : D 다시 한번 감사드립니다. 당신의 도움은 대단히 감사합니다. – deathsonic

+0

^_^당신은 환영합니다. –

관련 문제