视频播放不workig! [英] Video player not workig!

查看:132
本文介绍了视频播放不workig!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的整个$ C $下按钮点击播放视频,但每当我会点击一个按钮,然后一个消息框将显示在模拟器的屏幕上显示的是抱歉,该视频无法播放的消息。却不知道我要去的地方错了。

Trialvideo.java文件

 包android.com.trialvideo;

进口android.app.Activity;
进口android.graphics.PixelFormat;
进口android.media.MediaPlayer;
进口android.net.Uri;
进口android.os.Bundle;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.widget.Button;
进口android.widget.MediaController;
进口android.widget.VideoView;

公共类TrialVideoActivity延伸活动{
    / **第一次创建活动时调用。 * /

    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);

 / ** //视频看法:观看我们的视频
        VideoView视频=(VideoView)findViewById(R.id.surface_view);

        //设置视频路径,我们的视频(在这种情况下,人为猎豹gazalle.3gp)
        video.setVideoPath(/生/ jeewan.mp4);
        video.start();

    ** /
     最终按钮播放=(按钮)findViewById(R.id.play);
        play.setOnClickListener(新OnClickListener(){
            公共无效的onClick(视图V){
                视频播放器();

            }
        });}

        公共无效录像机(){

            。getWindow()和setFormat(PixelFormat.TRANSLUCENT);

            VideoView videoHolder =(VideoView)findViewById(R.id.surface_view);

            videoHolder.setMediaController(新的MediaController(本));

            videoHolder.setVideoPath(/ TrialVideo /生/ lic.3gp);

            videoHolder.requestFocus();
            videoHolder.start();

         }


    }
 

的main.xml文件

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    >
   <按钮
        机器人:layout_height =50dip
        机器人:文本=玩
        机器人:ID =@ + ID /播放
        机器人:layout_width =50dip
        >
        < /按钮>



< VideoView机器人:ID =@ + ID / surface_view
        机器人:layout_width =475px
        机器人:layout_height =440px
    />

< / LinearLayout中>
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    >
   <按钮
        机器人:layout_height =50dip
        机器人:文本=玩
        机器人:ID =@ + ID /播放
        机器人:layout_width =50dip
        >
        < /按钮>



< VideoView机器人:ID =@ + ID / surface_view
        机器人:layout_width =475px
        机器人:layout_height =440px
    />

< / LinearLayout中>
 

解决方案

喜试试下面的code:

VideoPlaying.java

 公共类VideoPlaying延伸活动{
    私人的MediaController MC;
    / **第一次创建活动时调用。 * /
    @覆盖
    公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);
    VideoView VD =(VideoView)findViewById(R.id.VideoView);
    开放的我们的uri = Uri.parse(android.resource://+ getPackageName()+/"+R.raw.VideoName);
    MC =新的MediaController(本);
    vd.setMediaController(MC);
    vd.requestFocus();
    vd.setVideoURI(URI);
    vd.start();
    }
    }
 

main.xml中

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:方向=垂直
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT安卓重力=中心>
< VideoView安卓layout_height =FILL_PARENT
机器人:layout_width =FILL_PARENT
机器人:ID =@ + ID / VideoView>< / VideoView>

< / LinearLayout中>
 

放置在原始文件夹中的视频和运行code。有时,视频将无法正确在模拟器上显示,尝试同时检查它在实际设备上。

here's my whole code for playing video on button click but whenever I'll click on a button then a message box will appear on the emulator screen and show's a "sorry, this video cannot be played" message. Don't konw where I am going wrong.

Trialvideo.java file

package android.com.trialvideo;

import android.app.Activity;
import android.graphics.PixelFormat;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.VideoView;

public class TrialVideoActivity extends Activity {
    /** Called when the activity is first created. */

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

 /**       // Video view: to view our video
        VideoView video = (VideoView) findViewById(R.id.surface_view);

        //set video path to our video(in this case man-cheetah-gazalle.3gp)
        video.setVideoPath("/raw/jeewan.mp4");
        video.start();

    **/    
     final Button play =(Button)findViewById(R.id.play);
        play.setOnClickListener(new OnClickListener(){
            public void onClick(View V){
                videoPlayer();

            }
        });}

        public void videoPlayer(){

            getWindow().setFormat(PixelFormat.TRANSLUCENT);

            VideoView videoHolder = (VideoView)findViewById(R.id.surface_view);

            videoHolder.setMediaController(new MediaController(this));

            videoHolder.setVideoPath("/TrialVideo/raw/lic.3gp");

            videoHolder.requestFocus();
            videoHolder.start(); 

         }


    }

main.xml File

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
   <Button 
        android:layout_height="50dip" 
        android:text="play" 
        android:id="@+id/play" 
        android:layout_width="50dip" 
        >
        </Button>



<VideoView android:id="@+id/surface_view" 
        android:layout_width="475px"
        android:layout_height="440px"
    />

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
   <Button 
        android:layout_height="50dip" 
        android:text="play" 
        android:id="@+id/play" 
        android:layout_width="50dip" 
        >
        </Button>



<VideoView android:id="@+id/surface_view" 
        android:layout_width="475px"
        android:layout_height="440px"
    />

</LinearLayout>

解决方案

Hi try the following code:

VideoPlaying.java

public class VideoPlaying extends Activity {
    private MediaController mc;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    VideoView vd = (VideoView) findViewById(R.id.VideoView);
    Uri uri = Uri.parse("android.resource://" + getPackageName() + "/"+R.raw.VideoName);
    mc = new MediaController(this);
    vd.setMediaController(mc);
    vd.requestFocus();
    vd.setVideoURI(uri);
    vd.start();
    }
    }

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:gravity="center">
<VideoView android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/VideoView"></VideoView>

</LinearLayout>

place the video on the raw folder and run the code. Sometimes video will not be correctly shown on the emulator, try to check it also on the actual device.

这篇关于视频播放不workig!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆