Still can't play the video on my android phone using video view -
i trying write very basic videoview play video in phone searched lot of posts , seek re-create code fails. says can't play video. there few lines of code still won't work, kind of frustrated. found code on youtube
the video in .3gp format tried export apk bundle phone (signed) created raw folder under res store testvideo going played. tried comment , comment 2 lines, both not working. //videoview.setmediacontroller(new mediacontroller(this)) //videoview.requestfocus()
package com.example.mymediaplayer; import java.io.ioexception; import android.app.activity; import android.media.mediaplayer; import android.net.uri; import android.os.bundle; import android.util.log; import android.widget.mediacontroller; import android.widget.videoview; public class videoviewactivity extends activity { @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.videoviewer); videoview videoview = (videoview)findviewbyid(r.id.videoview); string urlpath = "android:resource://"+ getpackagename() + "/" + r.raw.test; videoview.setvideouri(uri.parse(urlpath)); // videoview.setmediacontroller(new mediacontroller(this)); // videoview.requestfocus(); videoview.start(); } } here layout:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <videoview android:id="@+id/videoview" android:layout_width="match_parent" android:layout_height="wrap_content" /> </linearlayout>
this should work fine playing video.
videoview videoview = (videoview) view.findviewbyid(r.id.videoview); mediacontroller mediacontroller = new mediacontroller(getactivity()); mediacontroller.setanchorview(videoview); videoview.setmediacontroller(mediacontroller); videoview.setvideouri(video_uri); videoview.start(); make sure video format supported , path video correct. can test video play working streaming video instead of using stored file.
try playing demo video adding net permissions application , using uri video_uri : "https://archive.org/download/ksnn_compilation_master_the_internet/ksnn_compilation_master_the_internet_512kb.mp4"
android video
No comments:
Post a Comment