I am trying to play the video file .But it gives me error(1,-1004).I am not able to find what problem is .
Kindly help
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends Activity {
VideoView videoView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView= (VideoView)findViewById(R.id.video_view);
videoView.setVideoURI(Uri.parse("http://192.168.1.234/hls-live/livepkgr/_definst_/liveevent/livestream.m3u8"));
videoView.start();
}
}
// try this code
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends Activity {
VideoView videoView;
String VideoURL = "http://www.androidbegin.com/tutorial/AndroidCommercial.3gp";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
videoView= (VideoView)findViewById(R.id.video_view);
try {
MediaController mediacontroller = new MediaController(
MainActivity.this);
mediacontroller.setAnchorView(videoView);
Uri video = Uri.parse(VideoURL);
videoView.setMediaController(mediacontroller);
videoView.setVideoURI(video);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
videoView.requestFocus();
videoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
videoView.start();
}
});
}
}
Related
I wanted to make a program that would output a image fron the internet by a link to the screen, but the image either appears as a cropped strip, or does not appear at all. I will be very grateful for you help
code
package com.example.myapplication2;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
public class MainActivity extends AppCompatActivity {
private EditText s;
private TextView d;
private Button button1;
private URL link;
private InputStream j;
private Bitmap bitmap;
private ImageView image4;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
d = findViewById(R.id.textView12);
s = findViewById(R.id.editText1);
button1 = findViewById(R.id.button1);
image4 = findViewById(R.id.imageView3);
}
#Override
protected void onResume() {
super.onResume();
}
public void onClickStart(View view){
new Thread(new Runnable() {
#Override
public void run() {
try {
link = new URL(s.getText().toString());
try {
j = (InputStream)link.getContent();
}
catch (IOException e){
d.setText("fail");
}
}
catch (MalformedURLException e){
d.setText("fail");
}
runOnUiThread(new Runnable() {
#Override
public void run() {
bitmap = BitmapFactory.decodeStream(j);
image4.setImageBitmap(bitmap);
}
});
}
}).start();
}
}
enter image description here
enter image description here
It is possible in incorrect handling of the permission or file type, I would appreciate your help
I am getting an error for permission in the Bluetooth when I am using the command to disable.
please tell me why it's happening.
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.Manifest;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;
import java.util.Set;
public class MainActivity extends AppCompatActivity {
CheckBox enable;
private BluetoothAdapter BA;
private Set<BluetoothDevice> pairedDevices;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
enable = findViewById(R.id.enable_bt);
BA = BluetoothAdapter.getDefaultAdapter();
if (BA == null) {
Toast.makeText(this, "bluetooth not supported", Toast.LENGTH_SHORT).show();
finish();
}
if (BA.isEnabled()) {
enable.setChecked(true);
}
enable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
BA.disable();
}
}
}
I am new to android development, I think that something is wrong with the Uri built = Uri.parse("/storage/sdcard0/Download/");, but I don't know what. Any help would be appreciated.
package com.example.ecobinary;
import androidx.appcompat.app.AppCompatActivity;
import androidx.documentfile.provider.DocumentFile;
import android.content.Intent;
import android.content.res.AssetManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
public class MainActivity extends AppCompatActivity {
private static final int CREATE_FILE = 1;
private void createFile(Uri pickerInitialUri) {
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TITLE, "testing.txt");
intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, pickerInitialUri);
startActivityForResult(intent, CREATE_FILE);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button execute_button = findViewById(R.id.execute_button);
execute_button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Uri built = Uri.parse("/storage/sdcard0/Download/");
createFile(built);
}
});
}
}
I'm creating a sports app, but when I request location the buttons stop functioning.
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import java.util.HashMap;
import java.util.Map;
public class HomeActivity extends AppCompatActivity {
Button btnLogout;
Button btnBair;
Button btnVoir;
Button btzFair;
FirebaseAuth mFirebaseAuth;
private FirebaseAuth.AuthStateListener mAuthStateListener;
private int MY_PERMISSIONS_REQUEST_READ_CONTACTS ;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
btnLogout= findViewById(R.id.Logout);
btnBair= findViewById(R.id.button3);
btnVoir= findViewById(R.id.button4);
btzFair= findViewById(R.id.button5);
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(HomeActivity.this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
MY_PERMISSIONS_REQUEST_READ_CONTACTS);
return;
}
btnLogout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent hom= new Intent(HomeActivity.this, MainActivity.class);
startActivity(hom);
}
});
btzFair.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent fair= new Intent(HomeActivity.this, FutbolActivity.class);
startActivity(fair);
}
});
btnBair.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent hom= new Intent(HomeActivity.this, BasketActivity.class);
startActivity(hom);
}
});
btnVoir.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent hom= new Intent(HomeActivity.this, VoleiActivity.class);
startActivity(hom);
}
});
}
}
You have a return in your
if(ActivityCompat.checkSelfPermission(){...}
I dont think it should be there. Delete it and see what happens
This my code Don't know what is mistake in this code
But when i run this activity Can't play this video error is ocured.
package com.example.admin.educationforsocity;
import android.graphics.PixelFormat;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.VideoView;
import com.example.admin.educationforsocity.R;
public class VideoTutorial extends AppCompatActivity {
VideoView videoView;
MediaController mediaController;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_tutorial);
videoView = findViewById(R.id.video_view);
Button btn=(Button)findViewById(R.id.click);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Uri uri=Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.ksnn);
videoView.setVideoURI(uri);
videoView.start();
mediaController=new MediaController(VideoTutorial.this);
videoView.setMediaController(mediaController);
}
});
}
}
This is the error
Cant play this video