I am playing an RTSP live video stream on my android using Exoplayer media player. But here I am getting very high latency about 10 sec on it. Also after playing video is not clear there are stripes on it.
I have used Defaultloadcontrol on it too.
below is my code
DefaultRenderersFactory renderersFactory;
PlayerView playerView;
SimpleExoPlayer player = null;
DefaultBandwidthMeter defaultBandwidthMeter;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
playerView = findViewById(R.id.idExoPlayerVIew);
defaultBandwidthMeter = new DefaultBandwidthMeter();
DefaultLoadControl loadControl = new DefaultLoadControl.Builder().setBufferDurationsMs(2000, 2000, 2000, 2000).createDefaultLoadControl();
TrackSelector trackSelector = new DefaultTrackSelector();
#DefaultRenderersFactory.ExtensionRendererMode int extensionRendererMode = DefaultRenderersFactory.EXTENSION_RENDERER_MODE_PREFER;
renderersFactory = new DefaultRenderersFactory(this) .setExtensionRendererMode(extensionRendererMode);
ExoPlayer player = new SimpleExoPlayer.Builder(this,renderersFactory)
.setTrackSelector(trackSelector)
.setLoadControl(loadControl)
.build();
MediaSource mediaSource =
new RtspMediaSource.Factory()
.createMediaSource(MediaItem.fromUri("rtsp://192.168.222.188:8554/mystream"));
playerView.setPlayer(player);
player.prepare(mediaSource, true, false);
player.setPlayWhenReady(true);
}
Any kind of help will be grateful
Related
How to get the current video frame while playing video by libvlcsharp?
I can play video with libvlcsharp by the codes below:
public void OnAppearing()
{
LibVLC = new LibVLC();
var media = new LibVLCSharp.Shared.Media(LibVLC, new Uri("http://live.cgtn.com/1000/prog_index.m3u8"));
MediaPlayer = new MediaPlayer(LibVLC)
{
Media = media
};
media.Dispose();
Play();
}
private void Play()
{
if (m_url != string.Empty)
{
MediaPlayer.Play(new LibVLCSharp.Shared.Media(LibVLC, new Uri(m_url)));
}
}
You could use the TakeSnapshot method. However please note:
The snapshot will be written to the disk, there's no way to get the frame in memory in VLC 3 (A new API for that will likely come in VLC4)
This is not meant to grab every frame, use it only for a snapshot.
If you need more frames, have a look at the Thumbnailer samples. They're not meant to grab all frames either.
I want to play the Vimeo video in my android app by using Vimeo Official library : Vimeo networking library with the help of VideoView or ExoPlayer
The basic requirements for native playback are:
User must be logged in.
User must be the owner of the video.
User must be PRO or higher (or the app must have the "can access owner's video files" capability).
The token must have the video_files scope.
User must be the owner of the API app making the request.
Here is my complete code that helps me to play the video in android app by using Vimeo networking library
Presenting the final code
public class PlayActivity extends AppCompatActivity {
VideoView videoView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_play);
videoView = findViewById(R.id.player);
// Getting access Token
String accessToken = getString(R.string.access_token);
Configuration.Builder configBuilder = new Configuration.Builder(accessToken)
.enableCertPinning(false);
//Vimeo Client autenticated
VimeoClient.initialize(configBuilder.build());
// the video uri; if you have a video, this is video.uri
you should use URI in this format
eg. I use the URI in 2nd format
https://api.vimeo.com/me/videos/123456789
final String uri = "https://api.vimeo.com/me/videos/123456789";
VimeoClient.getInstance().fetchNetworkContent(uri, new ModelCallback<Video>(Video.class) {
#Override
public void success(Video video) {
Toast.makeText(PlayActivity.this, "Sucessful" + video, Toast.LENGTH_SHORT).show();
ArrayList<VideoFile> videoFiles = video.files;
Log.i("TAG1", "videoFiles " + videoFiles);
if (videoFiles != null && !videoFiles.isEmpty()) {
VideoFile videoFile = videoFiles.get(0); // you could sort these files by size, fps, width/height
String link = videoFile.getLink();
Log.i("TAG2", "link " + link);
// load link
// use the link to play the video by **EXO Player** or **Video View**
// Start your video player here
}
}
#Override
public void failure(VimeoError error) {
Log.i("TAG3", "vimeo error : " + error.getErrorMessage());
Toast.makeText(PlayActivity.this, "failure due to " + error.getErrorMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
Im new to android and very new to android plot. Can you point me to an example that uses FixedSizeEditableXYSeries?
My goal is to create a streaming plot that shows the latest sensor readings in an android app.
Thanks
===================Update - following discussion with #Nick====================
public class MainActivity extends AppCompatActivity {
// Create the redrawer so that the plot is updated
private Redrawer redrawer;
// create the message receiver - data is received via broadcasts
private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
// Get extra data included in the Intent
String message = intent.getStringExtra("CurrentHR");
Log.d("ReceivedHR ",message);
// Now put the new data point at the end of the FixedSizeEditableXYSeries, move all data points by 1.
for (int index=0;index<9;index++){
if(index<9){
hrHistory.setY(hrHistory.getY(index+1),index);
}else{
hrHistory.setY(Float.parseFloat(message),9);
}
}
}
};
// create a few references
private XYPlot xyPlot;
private FixedSizeEditableXYSeries hrHistory;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_heart_rate);
// Now find the plot views
xyPlot = (XYPlot)findViewById(R.id.xyPlot);
// Declare the local broadcast manager
LocalBroadcastManager.getInstance(this).registerReceiver(
mMessageReceiver, new IntentFilter("hrUpdate"));
// now put in some data
hrHistory = new FixedSizeEditableXYSeries("HR",10);
xyPlot.addSeries(hrHistory, new LineAndPointFormatter(Color.GREEN,Color.RED,null,null));
xyPlot.setRangeBoundaries(40, 120, BoundaryMode.FIXED);
xyPlot.setDomainBoundaries(0, 20, BoundaryMode.FIXED);
}
#Override
protected void onResume(){
super.onResume();
// set a redraw rate of 1hz and start immediately:
redrawer = new Redrawer(xyPlot, 1, true);
}
}
This gives me a nice graph but no line. It doesnt look like the plot is being updates as new data is filling the FixedSizeEditableXYSeries.
If you want scrolling behavior then FixedSizeEditableXYSeries would be the wrong choice; as your data scrolls you're essentially enqueueing the newest value and dequeuing the oldest value; a linked list type structure would be a better choice.
You can either implement XYSeries and back it with any suitable data structure you prefer, or you can use SimpleXYSeries, which already supports queue operations a la removeFirst() and addLast(...). There's a great example of of a dynamic scrolling plot in the demo app: OrientationSensorExampleActivity. Lines 235-245 show the specific actions mentioned above.
I'm using Aforge library to try to get a live stream from an IP Camera. My problem is, Frame rate is too slow and about one frame every 3 or 4 seconds! I have connected my camera directly to my computer through LAN port.
Here is my code :
JPEGStream stream;
public Form1()
{
InitializeComponent();
stream = new JPEGStream("http://192.168.1.88/pda.cgi?user=myusername&password=mypass&page=image&cam=1");
stream.NewFrame += stream_NewFrame;
}
private void stream_NewFrame(object sender, NewFrameEventArgs eventArgs)
{
Bitmap bmp =(Bitmap)eventArgs.Frame.Clone();
pictureBox1.Image = bmp;
}
private void button5_Click_1(object sender, EventArgs e)
{
stream.Start();
}
private void button9_Click(object sender, EventArgs e)
{
stream.Stop();
}
I don't know if it will count as an answer but, have you tried to edit the FrameInterval Property of the JPEGStream?.
Set that to 0 so you can get as many as frame as possible
stream.FrameInterval = 0;
But I'll suggest use the MJPEGStream instead of JPEGStream if your IP Cam is supporting it. It is faster than the JPEGStream
hi i am doing one app in android for all sizes of mobiles and tablets.imageviews displyed in all sizes good.but i facing problm in textview font size.in my app i need to display textview with that background and text,but different sizes text size is displaying not correctly.any one having idea pls help me. i tried using below code...
MainActivity .class
public class MainActivity extends Activity {
float screenHeight,screenWidth,screendensity;
RelativeLayout alpha_page2;
ImageView alpha_back,alpha_back1;
TextView option121;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
screenHeight = displaymetrics.heightPixels;
screenWidth = displaymetrics.widthPixels;
screendensity = displaymetrics.densityDpi;
Log.i("screenHeight",""+screenHeight);
Log.i("screenWidth",""+screenWidth);
Log.i("screendensity",""+screendensity);
setContentView(R.layout.activity_main);
int letpading=(int)(116*(screenWidth/1024));
int toppading=(int)(79*(screenHeight/600));
int textsiz=(int)(50*(screendensity/600));
option121 = (TextView)findViewById(R.id.text1);
option121.setBackgroundResource(R.drawable.dog_b_blank);
option121.setText("A");
option121.setText(Color.BLACK);
RelativeLayout.LayoutParams layoutoption121 = (RelativeLayout.LayoutParams) option121.getLayoutParams();
layoutoption121.height=(int)(180*(screenHeight/600));
layoutoption121.width=(int)(180*(screenWidth/1024));
layoutoption121.topMargin=(int)(100*(screenHeight/600));
layoutoption121.leftMargin= (int)(250*(screenWidth/1024));
option121.setPadding(letpading, toppading, 0, 0);
option121.setTextSize(textsiz);
}
}
Thats not the way do it. Android takes care of text size for you, use 'sp' (scale-independent pixel) units when specifying text sizes and if you need to configure different sizes for different screens have a read of this:
Supporting Multiple Screens
Basically, you need to define your text sizes in .xml files in the appropriate resource directory:
res/values-large
res/values-xlarge
etc..
Then refer to those constants in your layout xml or your code.