I tried to enable graphics acceleration but didn't worked for me
Here is my code
Click here to see
I am getting this error too click here too see
Please help me I am stuck
Can someone help me with the code
Probably you should use VideoView for this purpose. It allows to view videos from some url in fullscreen.
First, create a player activity xml file with VideoView:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<VideoView android:id="#+id/video_view"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
In your AndroidManifest.xml for your PlayerActivity set screenOrientation attribute to landscape:
<activity android:name=".PlayerActivity"
android:screenOrientation="landscape" />
Finally, in your PlayerActivity.kt set fullscreen flags and load your video url (or local file - check documentation):
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Fullscreen mode
requestWindowFeature(Window.FEATURE_NO_TITLE)
window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN)
setContentView(R.layout.activity_player)
// Load your video file
video_view.setVideoURI(Uri.parse(intent.getStringExtra(URL_TO_VIEW)))
video_view.setMediaController(MediaController(this))
video_view.requestFocus(0)
video_view.start()
}
Or if you write in Java, in your PlayerActivity.java:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Fullscreen mode
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_player);
// Load your video file
VideoView videoView = findViewById(R.id.video_view);
videoView.setVideoURI(Uri.parse(getIntent().getStringExtra(URL_TO_VIEW)));
videoView.setMediaController(new MediaController(this));
videoView.requestFocus(0);
videoView.start();
}
Related
I want to integrate a Banner Ad from Ironsource but have some problems to get it working.
This is the documentation, but I have problems to integrate it.
Thay say, that I have to write a bannerContainer, but how do I implement it in my XML-View like my main menu?
For this example to work you are going to need a .xml file, to describe this bannerContainer:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout
android:id="#+id/bannerContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:visibility="visible" />
</FrameLayout>
This file is in Project.Android/Resources/xml/bannerContainer.xml
After this, I have to add folowing code to my MainActivity:
protected void onCreate(Bundle savedInstanceState) {
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.Main);
// YOUR OTHER CODE //
// YOUR OTHER CODE //
// YOUR OTHER CODE //
IronSource.Init(this, "YOUR_APP_KEY", IronSource.AD_UNIT.Banner);
FrameLayout bannerContainer = FindViewById<FrameLayout>(Resource.Id.bannerContainer);
IronSourceBannerLayout mBanner = IronSource.CreateBanner(this, ISBannerSize.Banner);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MatchParent,FrameLayout.LayoutParams.WrapContent);
bannerContainer.addView(mBanner, 0, layoutParams);
but at this point
bannerContainer.addView(mBanner, 0, layoutParams);
The bannerContainer throws a NullReferenceException...
And still I dont know how to implement the banner in my "normal" views like in my MainMenu. All this code is in my project.Android, but I have my views in my pcl project, how to get access to the banner in the Android part?
Chris
I am using webview in my application where i am giving it a audio url.
Its working absolutely fine in some devices. see below screenshot:
But in some device its not looking user friendly.
Is there any way to set the size of webview audio player?
Update: Code snippet:
// open DOI activity
Intent podcastIntent = new Intent(mContext, DoiWebActivity.class);
podcastIntent.setAction(Constants.INTENT_VIEW_LINK);
podcastIntent.putExtra(Constants.EXTRA_DOI_LINK_URL, podcasts.get(0).getPodcastLink());
podcastIntent.putExtra(Constants.CALLING_FRAGMENT,Constants.CALLING_FRAGMENT_PODCAST_LISTING);
podcastIntent.putExtra(Constants.EXTRA_PODCAST_NAME,mContext.getString(R.string.podcast));
mContext.startActivity(podcastIntent);
//Called from podcastListingFragment : podcast name
if (bundle != null && bundle.containsKey(Constants.CALLING_FRAGMENT) &&
bundle.containsKey(Constants.EXTRA_PODCAST_NAME)) {
String title = bundle.getString(SilverChairConstants.EXTRA_PODCAST_NAME);
}
if (Utility.isNetworkAvailable(mActivity)) {
/**
* Showing external link.
*/
mWebView.loadUrl(mIntentText);
} else {
networkNotAvailable();
}
xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
tools:context=".fragments.WebFragment">
<WebView
android:layout_below="#+id/toolbar"
android:id="#+id/wv_webcontainer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!--progress bar-->
<include layout="#layout/silverchair_progress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignTop="#id/wv_webcontainer"
android:layout_alignBottom="#id/wv_webcontainer"/>
<include layout="#layout/empty_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerInParent="true"
/>
</RelativeLayout>
add this line in your code where you are initializing your webview. mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
If you have already done this I would recommend you to use MediaPlayer for straming.
MediaPlayer mediaPlayer = MediaPlayer.create(this, Uri.parse("http://vprbbc.streamguys.net:80/vprbbc24.mp3"));
mediaPlayer.start();
See this answer for more details about MediaPlayer streaming.
Out there, there are a lot of examples about how to play video on Android (API level 16).
But I can't understand why they don't work for me.
This is a simple example:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="my.owm.package" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".ContentActivity"
android:label="#string/title_activity_content" >
</activity>
</application>
</manifest>
activity_content.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="my.owm.package.ContentActivity"
android:orientation="vertical">
<VideoView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/videoView"
android:layout_gravity="center_horizontal" />
</LinearLayout>
contentActivity.java
public class ContentActivity extends Activity {
private static final String TAG = ContentActivity.class.getSimpleName();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_content);
VideoView videoView =(VideoView) findViewById(R.id.videoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setVideoPath("/sdcard/Movies/test.mp4");
videoView.setMediaController(mediaController);
videoView.requestFocus();
videoView.start();
}
}
The test.mp4 files is actually there and runs fine with any player (btw it's a H264 w/ Baseline Profile). Anyway i tried several other videos, most of them used by the authors of the tutorial on this topic.
I get no errors but no video and no audio.
I'm pretty sure I'm missing something obvious because I found this code in a lot of Android tutorials!
Any idea?
Thanks!
EDIT:
I run the code on a physical device.
However I discovered the code is actually working until I add the following item in the layout xml file:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_margin="0dp" />
I worked on this way :
public class AnVideoView extends Activity {
String SrcPath = "/sdcard/Video/Android in Spaaaaaace!_low.mp4";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
VideoView myVideoView = (VideoView)findViewById(R.id.myvideoview);
myVideoView.setVideoPath(SrcPath);
myVideoView.setMediaController(new MediaController(this));
myVideoView.requestFocus();
myVideoView.start();
}
}
I also have come across issues with VideoView like this across multiple devices before.
Firstly I would consider re-encoding your videos using a tool such as ffmpeg that can be downloaded here.
The following encoding has always worked for me:
ffmpeg -i input.mp4 -c:v libx264 -profile:v baseline -c:a libfaac -ar 44100 -ac 2 -b:a 128k -movflags faststart output.mp4
Alternatively, some devices cannot handle videos with 'large' dimensions. Try resizing your videos to a smaller size and seeing if that helps also.
SOLVED: the DrawerLayout should be added at the END of the layout... it seems the order is important!
I'm trying to play YouTube video in my application using WebView.
But when I click "Play" the application crashes.
This is my code:
public class Youtube extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.a_video_item);
WebView videoView = (WebView)findViewById(R.id.videoView);
TextView tvTitle = (TextView) findViewById(R.id.VideoTitle);
WebSettings videoViewSettings = videoView.getSettings();
videoViewSettings.setJavaScriptEnabled(true);
videoViewSettings.setPluginState(WebSettings.PluginState.ON);
videoView.setWebChromeClient(new WebChromeClient());
String youtubeID ="XSzE2LLFluE";
tvTitle.setText(youtubeID);
videoView.loadUrl("http://www.youtube.com/embed/" + youtubeID +"?autoplay=1&vq=small");
}
}
And this is my XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
android:id="#+id/videoView"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_below="#+id/VideoTitle"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"/>
<TextView
android:id="#+id/VideoTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="#string/imgdesc"
android:layout_marginRight="10dp"/>
</RelativeLayout>
I'm testing the project with Nexus 5 on Android Studio emulator.
You have to add the two lines of code:
webView.getSettings().setPluginsEnabled(true); webView.getSettings().setJavaScriptEnabled(true);
this will solve the problem. Try it and tell.
I found the issuse.
Beacuse I did the tests on Emulator without Youtube app its crashes.
On a device with Youtube app its working fine.
Now its crasheswhen i click on 'Full screen' button
I am a beginner in android development.
I was trying to display a video with surface view using media codec for which i am successful.
Now I want to add one more video at run time which has to be displayed or hidden as per the wish of the user or to switch between the two.
Can I have some suggestions for the same...
Thanks......
Try this
public class CustomPictureActivity extends Activity {
/** Called when the activity is first created. */
VideoView vd1,vd2;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
vd1=(VideoView) findViewById(R.id.v1);
vd2=(VideoView) findViewById(R.id.v2);
vd1.setVideoURI(Uri.parse("/mnt/sdcard/file.mp4"));
vd1.setMediaController(new MediaController(this));
vd1.requestFocus();
vd1.start();
vd2.setVideoURI(Uri.parse("/mnt/sdcard/android.mp4"));
vd2.setMediaController(new MediaController(this));
vd2.requestFocus();
vd2.start();
}
}
Your xml code should be like this:
<?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="horizontal" >
<VideoView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:id="#+id/v1"/>
<VideoView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:id="#+id/v2"/>
</LinearLayout>
May this will help you.