java


Video isn't shown only audio on android


I am trying to show video in the middle of the screen but I can only hear audio and there is no video.
I added buttons to the framelayout but the buttons are shown (the video isnt)
this is my xml
<FrameLayout
android:layout_width="776dp"
android:layout_height="365dp"
android:layout_gravity="center"
android:id="#+id/videoLayout"
android:visibility="gone">
<SurfaceView
android:id="#+id/arVideoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="1"
android:layout_gravity="center"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom|center_horizontal">
<Button
android:text="Stop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/buttonStop"
android:onClick="stopPlaying"/>
<Button
android:text="play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/buttonPlay"
android:layout_toRightOf="#+id/buttonStop"
android:onClick="StartPlaying"/>
<Button
android:text="Start"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:id="#+id/buttonStart"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/buttonPlay"
android:onClick="MovieFromStart"/>
</RelativeLayout>
</FrameLayout>
and this is my code:
public boolean Run(Model currentModel, Activity act) {
_act = act;
final FrameLayout rlVideo = (FrameLayout) act.findViewById(R.id.videoLayout);
final String str = Environment.getExternalStorageDirectory()+ "/sfmModelTracker/ex3/Models/" + currentModel.id + "/"+ clip.VideoName;
final SurfaceView tv = (SurfaceView) act.findViewById(R.id.arVideoView);
tv.setZOrderOnTop(true);
try {
tv.setZOrderOnTop(true);
player.setDataSource(str);
tv.setZOrderOnTop(true);
player.setDisplay(tv.getHolder());
tv.setZOrderOnTop(true);
} catch (Exception e) {
e.printStackTrace();
}
player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
// Adjust the size of the video
// so it fits on the screen
int videoWidth = player.getVideoWidth();
int videoHeight = player.getVideoHeight();
float videoProportion = (float) videoWidth / (float) videoHeight;
int screenWidth = rlVideo.getWidth();
int screenHeight = rlVideo.getHeight();
float screenProportion = (float) screenWidth / (float) screenHeight;
android.view.ViewGroup.LayoutParams lp = tv.getLayoutParams();
if (videoProportion > screenProportion) {
lp.width = screenWidth;
lp.height = (int) ((float) screenWidth / videoProportion);
} else {
lp.width = (int) (videoProportion * (float) screenHeight);
lp.height = screenHeight;
}
tv.setLayoutParams(lp);
if (!player.isPlaying()) {
player.start();
tv.setZOrderOnTop(true);
}
}
});
player.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
#Override
public void onCompletion(MediaPlayer mp)
{
ScreenManager.getInstance( null ).StopPlaying();
}
});
tv.setZOrderOnTop(true);
try {
player.prepare();
tv.setZOrderOnTop(true);
rlVideo.setVisibility( View.VISIBLE );
//rl.setVisibility(View.VISIBLE);
tv.setVisibility( View.VISIBLE );
} catch (IOException e) {
e.printStackTrace();
}
//player.start();
//tv.sur
return false;
}
what am I doing wrong? (I already tried Set Z - didnt work)
thank you!
Try using the below snippet.
VideoView play = (VideoView) view.findViewById(R.id.play);
MediaController mediaController = new MediaController(mContext);
mediaController.setAnchorView(play);
Uri video = Uri.parse("");
play.setMediaController(mediaController);
play.setVideoURI(video);
play.start();
play.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (play.isPlaying()) {
play.pause();
} else if (!play.isPlaying()) {
play.start();
}
}
});
The xml would be :
<?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="wrap_content"
android:orientation="vertical"
<VideoView
android:id="#+id/play"
android:layout_width="match_parent"
android:layout_height="#dimen/height" />
</LinearLayout>

Related Links

Making text follow your cursor inside a JPanel
Migrating from Tomcat 6.0 to WebSphere 8.5
What problems might arise when adding JComponents to a component
JavaPNS alternatives?
Property file acting odd with the put and remove methods
Finding the max value in and Array
How to properly store end date in database
Java: Vector with multiple generics
Reflection generic get field value
Weird behaviour of Calendar and DateFormat
GWT. Exclude shared domain objects to separate Maven module
How do I fix Javadoc that no longer autofills/autocompletes?
Advice wanted on a complex structure in java (DAO and Service Layer linking/coupling)
Iterate through binary search tree to find all leaves
Not allowed to include a default constructor - Java Basics
Grabbing ints from a string in java

Categories

HOME
sendgrid
osgi
proxy
magnific-popup
comparison
xmpp
at-command
leon
umd
icloud
basic
imacros
u-sql
windows-server-2012
ups
tostring
facebook-page
beyondcompare
samoa
contextmenu
autocad-plugin
tokenize
orleans
cloudhub
ehcache
tapestry
realex-payments-api
language-agnostic
pepper
pingfederate
nouislider
socialengine
media-queries
key-value-observing
titanium-mobile
google-sites-2016
geopositioning
mapdb
html5-fullscreen
automake
espeak
android-browser
temporary-files
sql-server-agent
powershell-dsc
isbn
keydown
sencha-touch-2.3
logfiles
google-datalayer
jedis
typescript1.8
lowpass-filter
brightcove
setter
forever
np-complete
imanage
crosswalk-runtime
xcb
jquery-filter
static-ip-address
mathematica-frontend
etsy
whois
fadeout
srand
reactive-banana
cartesian-product
endeca-workbench
t4mvc
qdialog
emailrelay
php-ci
arcanist
interrupted-exception
myo
method-parameters
oberon
angular-local-storage
clipperlib
python-green
typekit
qpainter
javafx-webengine
socketexception
flask-cors
heisenbug
jquery-layout
doskey
valuechangelistener
picturefill
bundles
ccss
listings
sabredav
datawindow
netbeans-6.9
vdsp
joyent
xdomainrequest
cinema-4d
winbugs14
propagation
imac
telerik-scheduler
mozilla-prism
modelstate
asp.net-profiles
multi-tier
compiler-specific
yagni
phonon
zend-decorators
thread-local-storage
ubuntu-9.04
django-notification

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App