I have checked the similar questions but they did not seem to solve the purpose hence asking the question along with the code logic.
I am able to get a REST url from S3 of format : https://s3.amazonaws.com/{bucket}/file.MOV?Signature=xyz&Expires=abc&AWSAccessKeyId=lmn
Now I need the Media player to play(stream) this video.
My Code :
MediaPlayer mp = new MediaPlayer();
try {
mp.setDataSource(urlS3REST);
mp.prepare();
mp.start();
}
catch{...}
The Error thrown here is : Prepare failed. : status=0x105
Any suggestions?
const PVMFStatus PVMFErrRTSP458ParameterIsReadOnly = (-105);
You might not have permission to write to the file,Files can only be read.
Related
I am trying to load a video file at runtime and play that video using the Unitys Video player component.The video is located in a folder on the mobile. i receive the URL to the file location(this is tested correct). While looking for the file Unity even finds the file at location but is not able to play it. I receive the following error :
AndroidVideoMedia: Error opening extractor: -10002
There is nothing on the internet regarding this issue as well. One page said something about changing gradle version.
Please note that this works fine on the editor. I have also noticed if putting a file in the persistent data path of the app, then loading and playing is fine. But if the file is kept in any other custom folder, then even after finding the video Unity is not able to play it.
Following is a snippet of the code :
void Start()
{
StartCoroutine("LoadVideoRoutine");
}
IEnumerator LoadVideoRoutine()
{
if(video==null)
yield return null;
string root = _arManager.VideoURLToPlay;
print("This is video url : " + root);
if(!File.Exists(root))
{
print("no video");
yield return null;
}
else if(File.Exists(root))
{
print("Found vid");
video.url = root;
video.Prepare();
// video.Play();
}
while(!video.isPrepared)
{
print("preparing");
yield return null;
}
print("playing");
video.Play();
// video.url = root;
// video.Play();
}
Following is a sample URL where the video is present :
"/storage/emulated/0/MyApp/RaceRecordings/3D2A4AF9-A6EB-4D48-92D2-1B2A6ADC968A.mp4"
In the logs, I got the "Found vid" log indicating that unity finds the file. But immediately when I am setting the URL I got the error.
I am not sure what this is and would appreciate some help in this regard.
Maybe try remove the .mp4. Maybe it doesn't belong to the URL but I don't know much about it.
use thisMagic Exo player library.
can play online and offline video and handle initializing and deint the payer on its own
I am trying to run media through android mediaplayer with some API link (thus doesn't have .mp3 in the end of url) as follows:
android code :
headers.put("token", token_value);
myPlayer.setDataSource(
getApplicationContext(),
Uri.parse(url),//url : http://basedomain.com/api/getmp3
headers
);
backend laravel code :
$song_path = "abc.mp3";
$path = storage_path().DIRECTORY_SEPARATOR."somefolder".DIRECTORY_SEPARATOR.$song_path;
$response = new BinaryFileResponse($path);
return $response;
I am getting the binary response from laravel code(tested through postman), however android code is not playing the music from laravel response.
android issue list :
1) W/MediaPlayer: Couldn't open http://basedomain.com/api/getmp3: java.io.FileNotFoundException: No content provider: http://basedomain.com/api/getmp3
2) E/MediaPlayer: error (1, -2147483648)
I've just tried the following code in Android studio targeting Android SDK 28 and it works fine. Make sure your API is actually returning the mp3 file.
Android MediaPlayer docs
try {
MediaPlayer player = new MediaPlayer();
player.setDataSource("https://yourdomain/yourmusic.mp3");
player.prepare();
player.start();
} catch (IOException e) {
e.printStackTrace();
}
Try testing your code using a url to a known public mp3 file to verify that the MediaPlayer code is correct. Once that is working, you can narrow the issue down to either the token not being set correctly or your server not returning the mp3 file correctly. Maybe the response doesn't indicate it is an mp3 file correctly and thus the media player doesn't know how to handle it.
I finally found the reason behind this issue. My backend laravel api call was a POST request. Changing the same to Get request worked for me.
Also changing request from POST to GET was not an issue as my request parameters were sent through the header. (This was done because android mediaplayer's setDataSource method only accepts headers and not body parameters).
In short android mediaplayer is expecting us to use GET request only.
I know there are lots of similar problems to mine, but for some reason the answers to those questions don't seem to work. I am using android and have a sound file named 'backgroundbeat.wav' and I'm trying to import it but instead I get the error:
"failed to open file 'res\raw\backgroundbeat.wav'. (No such file in directory)"
Here is the code where I use the media player:
mp = new MediaPlayer();
try{
mp.setDataSource("res/raw/backgroundbeat.wav");
mp.prepare();
mp.start();
}catch(Exception e){
e.printStackTrace();
}
Use your app package name to define the correct path :
mp.setDataSource("android.resource://<YOURPACKAGE_NAME>/raw/backgroundbeat");
example:
mp.setDataSource("android.resource://com.jorgesys.myapp/raw/backgroundbeat");
or other way to load a media file from /raw folder, if you are inside an activity you could use:
mp = MediaPlayer.create(this, R.raw.backgroundbeat);
or You can use a VideoView to play your file
Videoview on splash screen
Not much experienced in this but you can try to use mediaPlayer.setDataSource(FileDescriptor fd) instead of mediaPlayer.setDataSource(String path). See MediaPlayer setDataSource, better to use path or FileDescriptor? . Apparently if you call prepare() while using string as a parameter to setDataSource, it is causing some issues as per the answers.
You may try something like:
// Use the proper context instead of *context* variable
InputStream in = context.getResources().openRawResource(R.raw.backgroundbeat);
mediaPlayer.setDataSource(in.getFD())
Let me know if it helps.
I'm using a book called Android Wireless Application Development 2nd edition 2009 (L.Darcey & S.Conder, published by Addison Wesley) as my literature for a course I'm currently doing in Android app development. In the third chapter of this book you use the MediaPlayer class to initiate a media player object to stream mp3 files to your app using to this method below.
public void playMusicFromWeb() {
try {
Uri file = Uri.parse("http://downloads.bbc.co.uk/podcasts/6music/adamandjoe/adamandjoe_20111231-1430a.mp3");
mp = MediaPlayer.create(this, file);
mp.start();
}
catch (Exception e) {
Log.e(DEBUG_TAG, "Player failed", e);
}
}
Happy days, this all works just fine in API 8 (which is what the book uses). However trying to use this method in a higher API, especially 15 which is (on writing) the latest API available I get a NullPointerException thrown. Debugging makes me none the wiser as the file variable seems to hold the string value fine, but it won't translate into a functional mp3 stream. I have tried various different approaches using prepare(); prepareAsync(); setDataSource(); reset(); etc., however nothing seems to work. You'd think that my teachers would be able to help me out, but they apparently don't know what to do either.
I now assume that this way of streaming must be obsolete in higher API's than 8. I would be very grateful if someone could shine a light on how to stream an mp3 file in API 15.
I think you have to do more than that. Here is an example for doing what you want:
The Header's content-type of the URL could be bad.
You could try this syntax:
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(URL_OF_FILE);
mp.prepare();
mp.start();
See if the NullPointerException remains.
You could also view a more recent tutorial on this particular subject.
It was as simple as adding this line:
<uses-permission android:name="android.permission.INTERNET" />
to the manifest file!
hi guys i read many example about play video in video view, but no one work for me, i get this error:
java.io.FileNotFoundException: /android.resource:/frt.com.maint/2130968576 (No such file or directory)
this is my code-------------------------------------------------------------------------:
FileInputStream fi = new FileInputStream("android.resource://frt.com.maint/" + R.raw.videointro);
MediaPlayer pl = new MediaPlayer();
pl.setDataSource(fi.getFD());
pl.prepare();
pl.start();
MediaPlayer don't have method setVideoURI, i use the first solution that you give me but i still get same error, after i use this code with videoview:
Uri video = Uri.parse("android.resource://frt.com.maint/videointro");
vidview_gdf.setVideoURI(video);
vidview_gdf.start();
but i get an error with message "you can not play the video"
p.s: additional info: introvideo.mp4 - 7 MB
You're trying to use the ID of the resource, which is just an int index.
Use the filename instead:
fi = new FileInputStream("android.resource://frt.com.maint/nitrovideo");
Or better:
StringBuilder videoURIPath = new StringBuilder();
videoURIPath.append("android.resource://");
videoURIPath.append(getPackageName() + "/");
videoURIPath.append("raw/");
videoURIPath.append(videoFileName);
pl.setVideoURI(Uri.parse(videoURIPath.toString());
Where videoFileName is a string of the name of your file.
Are you doing this on emulator or actual device?
I had a bit of bad experience with H.264 encoded video before. Basically, I tried to play it on the first GalaxyTab but it didn't work. Turned out that GalaxyTab I had didn't support H.264.
So, I would advise you to make sure that the default video player can play this file before proceed further. If that's not the case for you then I'm not sure what's wrong. Your code looks fine to me.