开发者

Android: How can i play Video in the internal MediaPlayer from a Resource, Can anyone Help?

I am trying to play a mp4 video from the resource within the app, either res/raw or assets, but i a开发者_运维知识库m having no luck, nor can i find any tutorials or solutions that work anywhere, hoping someone hear can provide the answer.

Code below that i thought would work but doesnt, please show me how?

Thanks Lucy

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.video);    

    final Button button = (Button) findViewById(R.id.play);  
         button.setOnClickListener(new Button.OnClickListener() {  
             public void onClick(View v) {  
                 Uri uri = Uri.parse("android.resource://com.video.play.test/" + R.raw.test2);
                 Intent intent=new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, "video/mp4");
                 startActivity(intent);  
             }
         });  
}


Please check this answer on that subject:

https://groups.google.com/group/android-developers/browse_thread/thread/9a934f3aa2e4256/577d991b0f94aaf2?hl=hr&lnk=gst&q=play+video+resources#577d991b0f94aaf2

What I have managed was to play video from resources in my application (SufraceView in my layout). Another approach is (as suggested in the link) to copy video to SD card and easily play it from there using internal (system) MediaPlayer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜