Can android directly play Dynamic HTTP streaming using flash manifest file (.f4m) - android

I'm trying to make an app that plays live http streaming on android (i already did the same in iphone). The Android official tutorial shows a sample code on how to do http live streaming, which i followed:
public class liveStream extends Activity implements OnClickListener {
Button streamButton;
MediaPlayer mediaPlayer = null;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_live_stream);
streamButton = (Button) findViewById(R.id.streamButton);
streamButton.setOnClickListener(this);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_live_stream, menu);
return true;
}
public void onClick(View v) {
String url = "http://d2233avv69kunu.cloudfront.net/hds-live/livepkgr/_definst_/liveevent/livestream.f4m";
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(url);
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
mediaPlayer.prepare();
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.start();
}
}
thing is I keep on getting an IOException when i try to prepare the player.. I did some research and it appears that I will need to play this off a flash client from my android? If that's so, how can I play live http streaming directly without the third party flash player? Similar to iphone

Android doesn't support flash manifest file (.f4m) live streaming.
Android supported format for streaming

Most android devices from 2.3 on natively support Apple's HLS in some form or another . There are some devices where you'll need to use httplive://.../playlist.m3u8 instead up http://, but as far as I can tell, most devices support an m3u8 URL with just http, especially once you get past Android 3.0

Related

Is voice call recording back with android 10 (2019)?

I'm really interested in call recording in android. But as you already know android officially shuts off voice call recording in android 9. But just after the release of Android 10(sept 3 2019), while going through their new release notes, I came across the following page which looked promising, in terms of call recording.
https://developer.android.com/guide/topics/media/sharing-audio-input.
Here regarding voice call recording following things can be seen.
Voice call + ordinary app
A voice call is active if the audio mode returned by AudioManager.getMode() is MODE_IN_CALL or MODE_IN_COMMUNICATION.
Android shares the input audio according to these rules:
The call always receives audio.
The app can capture audio if it is an accessibility service.
The app can capture the voice call if it is a privileged (pre-installed) app with permission CAPTURE_AUDIO_OUTPUT.
To capture the voice call's uplink (TX), downlink (RX), or both, the app must specify the audio sources MediaRecorder.AudioSource.VOICE_UPLINK or MediaRecorder.AudioSource.VOICE_DOWNLINK, and/or the device AudioDeviceInfo.TYPE_TELEPHONY.
So after reading this I tried to capture audio inside an accessibility service. Here's my code.
Accessibility service
public class MyAccessibilityService extends AccessibilityService {
FrameLayout mLayout;
public MyAccessibilityService() {
}
#Override
public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
}
#Override
public void onInterrupt() {
}
#Override
protected void onServiceConnected() {
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
mLayout = new FrameLayout(this);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.type = WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
lp.format = PixelFormat.TRANSLUCENT;
lp.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.TOP;
LayoutInflater inflater = LayoutInflater.from(this);
inflater.inflate(R.layout.action_bar, mLayout);
wm.addView(mLayout, lp);
configureStartRecording();
configureStopRecording();
}
private void configureStartRecording() {
Button startRecordingButton = mLayout.findViewById(R.id.btnStartRecording);
startRecordingButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
CustomMediaRecorder recorder = CustomMediaRecorder.getInstance();
File audiofile = null;
String out = new SimpleDateFormat("dd-MM-yyyy hh-mm-ss").format(new Date());
File sampleDir = new File(getExternalFilesDir(null), "/TestRecordingDasa1");
if (!sampleDir.exists()) {
sampleDir.mkdirs();
}
String file_name = "Record";
try {
audiofile = File.createTempFile(file_name, ".amr", sampleDir);
} catch (IOException e) {
e.printStackTrace();
}
recorder.getRecorder().setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
recorder.getRecorder().setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
recorder.getRecorder().setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.getRecorder().setOutputFile(audiofile.getAbsolutePath());
try {
recorder.getRecorder().prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
recorder.start(getApplicationContext());
Log.i(MainActivity.LOG_PREFIX, String.format("Recording started. Saving to path: '%s'", audiofile.getAbsolutePath()));
}
});
}
private void configureStopRecording() {
Button button = mLayout.findViewById(R.id.btnStopRecording);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
CustomMediaRecorder recorder = CustomMediaRecorder.getInstance();
recorder.stop();
}
});
}
And The accessibility service config has the following configs
android:accessibilityFeedbackType="feedbackGeneric"
android:accessibilityFlags="flagDefault"
android:canPerformGestures="true"
android:canRetrieveWindowContent="true"
So here are my observations.
1. Still we cannot set MediaRecorder.AudioSource.VOICE_DOWNLINK and VOICE_UPLINK audio sources. It fires an exception.
2. When MediaRecorder.AudioSource.VOICE_COMMUNICATION and MediaRecorder.AudioSource.MIC is given mic input prior to starting the call and after disconnecting the call is recorded.
So it looks like we are not getting any stream from the call even from an accessibility service. I tried this on a pixel 3A xl device which is newly updated to android 10.
So after reading this, and after my failed trial I have following questions...
What does this new behavior for android 10 really mean. What is the relevance here for an accessibility service? Which I tried and already failed?
Have I done anything wrong during configuring the accessibility service?
If this approach does not solve call recording issue is android 10 also missing with the call recording feature? Or is there any other way of doing it in android 10. Because I'm only interested in call recording in android 10.
In a nutshell I just want to know whether voice call recording is back with android 10...
First of all thanks for your code. I tried with the same code and I have used MediaRecorder.AudioSource.VOICE_RECOGNITION and I am getting both side call recording in Samsung S10, Oneplus 7 and Real Me.

chromecast "failed to start application: no application is running" after called startSession()

I'm testing playing online video using chromecast.
After onRouteSelected(), I create the ApplicationSession and attach a MediaProtocalMessageStream;
Then I called mSession.startSession(); with no APP_ID, so I assume the build-in app inside chromecast play the video for me. This code works perfect and I can play online mp4 videos without writing my own receiver.
But, When I try to leave the video play app, I can't go back anymore, there is always an error message comes from onSessionStartFailed() which says
StartSessionTask failed with error: failed to start application: no
application is running
I don't remember how the first time I got into the video play app, which I don't leave for few day.
But I do know how I leave it, Here is what I did before I can never startSession again:
open Youtube app, get a deviced connected
play some youtube videos
disconnected from a chormecast, then the chromecast return to the starting page
So, doesn't anybody know what's going on here? How to open the build-in video app again?
By the way, My chromecast get a system update just after I return to the starting page, I don't know if google update something cause startSession() fail.
Below is the code I startSession and attach a mediaStream.
mSession = new ApplicationSession(mCastContext, mSelectedDevice);
ApplicationSession.Listener listener = new ApplicationSession.Listener() {
#Override
public void onSessionStarted(ApplicationMetadata appMetadata) {
mChannel = mSession.getChannel();
mStream = new MediaProtocolMessageStream();
mChannel.attachMessageStream(mStream);
if (mStream.getPlayerState() == null) {
ContentMetadata metaData = new ContentMetadata();
metaData.setTitle("Test Video");
String url = "http://www.auby.no/files/video_tests/h264_720p_hp_5.1_6mbps_ac3_planet.mp4";
try {
mCommand = mStream.loadMedia(url, metaData, true);
mCommand.setListener(new MediaProtocolCommand.Listener() {
#Override
public void onCompleted(MediaProtocolCommand arg0) {
onSetVolume(0.5);
}
#Override
public void onCancelled(MediaProtocolCommand arg0) {
}
});
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
#Override
public void onSessionStartFailed(SessionError error) {
Log.d("TEST", "Session Started failed");
}
#Override
public void onSessionEnded(SessionError error) {
Log.d("TEST", "Session Started end");
}
};
mSession.setListener(listener);
try {
mSession.startSession();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
You will have to use your own app id and own receiver. Google's default receiver doesn't play video streams anymore (it used to). It only handles Chrome tab mirroring now.

Web view unable to show webpage

public class MyPlayer extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(akki.player.R.layout.main);
boolean flashInstalled = false;
try {
PackageManager pm = getPackageManager();
ApplicationInfo ai = pm.getApplicationInfo("com.adobe.flashplayer", 0);
if (ai != null)
flashInstalled = true;
} catch (NameNotFoundException e) {
flashInstalled = false;
}
if(flashInstalled){
WebView browser=(WebView) findViewById(akki.player.R.id.webView1);
//
browser.getSettings().setJavaScriptEnabled(true);
;
browser.getSettings().getPluginsEnabled();
browser.getSettings().setAllowFileAccess(true);
browser.getSettings().setAppCacheEnabled(false);
browser.loadUrl("http://sound30.mp3pk.com/indian/dabangg2/[Songs.PK]%2004%20-%20Saanson%20Ne%20-%20Dabangg%202.mp3");
Toast.makeText(this, "Flash Player installed ....", 1).show();
}
else
{
Toast.makeText(this, "Install Flash Player First ..", 1).show();
}
}
this is my code to play a song from website. but it says webpage not available.
what is the possible error.?
thanx in advance.
i have a player.html file linking a player to the website as well.
the code is working fine as it asks to install flash player as mentioned in the code but when i launch the application it just not displays the webpage. Instead it says webpage not available.
I think that you should download it and play it with Mediaplayer. I see that you try to use Flash player, but Flash player isnt unsupported:
http://arstechnica.com/gadgets/2012/06/no-flash-for-android-4-1-no-new-installs-after-august-15/
The main thing is that you putting mp3 file in webview. You can change your link to http://www.musikmaza.com/2012/11/dabangg-2-2012-latest-hindi-mp3-songs.html . After changing link check that page is showing or not.
Either if you want to play mp3 files then you need a downloadManager for downloading mp3 file and then MediaPlayer for playing that file.

How to play m3u8 on Android?

As i understood, Android 3.0 and above are able for play radio streaming m3u8 - http://developer.android.com/guide/appendix/media-formats.html
I put this link - http://content.mobile-tv.sky.com/content/ssna/live/ssnraudio.m3u8 into MediaPlayer but in LogCat i get:
06-01 09:04:44.287: INFO/LiveSession(33): onConnect 'http://content.mobile-tv.sky.com/content/ssna/live/ssnraudio.m3u8'
06-01 09:04:44.287: INFO/NuHTTPDataSource(33): connect to content.mobile-tv.sky.com:80/content/ssna/live/ssnraudio.m3u8 #0
06-01 09:04:44.747: INFO/NuHTTPDataSource(33): connect to content.mobile-tv.sky.com:80/content/ssna/live/ssnraudio.m3u8 #0
06-01 09:04:45.019: INFO/NuHTTPDataSource(33): connect to content.mobile-tv.sky.com:80/content/ssna/live/ssnraudio/ssnr_052311_071632_78731.aac #0
**06-01 09:04:45.817: ERROR/LiveSession(33): This doesn't look like a transport stream...**
06-01 09:04:45.967: INFO/HTTPLiveSource(33): input data EOS reached.
This is my source code:
mp = new MediaPlayer();
start.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
try {
mp.setDataSource("http://content.mobile-tv.sky.com/content/ssna/live/ssnraudio.m3u8");
mp.prepare();
mp.start();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
stop.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
mp.stop();
mp.reset();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
Following this link trail:
http://code.google.com/p/android/issues/detail?id=14646
->
http://code.google.com/p/android/issues/detail?id=16884
->
http://code.google.com/p/android/issues/detail?id=17118
(ARGGGGH!)
Gives the answer in the end:
basically in Android v2.3 & v3.0, use the non-standard httplive:// scheme,
in 3.1 use http:// but with some code workaround in how you call the relevant methods in the media framework.
Try ExoMedia, streaming is as easy as:
emVideoView.setVideoURI(Uri.parse("https://archive.org/download/Popeye_forPresident/Popeye_forPresident_512kb.mp4"));
I works well with m3u8.
Maybe you can try the Vitamio plugin, http://vov.io/vitamio/
Vitamio is a multimedia framework for all Android devices. Vitamio works like the Android's default MediaPlayer except that it includes much more powerful features. And it's absolutely free !
Network Protocols
The following network protocols are supported for audio and video playback:
MMS
RTSP (RTP, SDP)
HTTP progressive streaming
HTTP live streaming (M3U8), for Android 2.1+
This is my example of how to play .M3U8 Streaming in Android
activity_main.xml
<?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="wrap_content"
android:orientation="vertical" >
<VideoView
android:id="#+id/myVideoView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Main.java
package com.grexample.ooyalalive;
import java.net.URL;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;
public class Main extends Activity {
private String urlStream;
private VideoView myVideoView;
private URL url;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_vv);//***************
myVideoView = (VideoView)this.findViewById(R.id.myVideoView);
MediaController mc = new MediaController(this);
myVideoView.setMediaController(mc);
urlStream = "http://jorgesys.net/i/irina_delivery#117489/master.m3u8";
runOnUiThread(new Runnable() {
#Override
public void run() {
myVideoView.setVideoURI(Uri.parse(urlStream));
}
});
}
}
I have seen a lot of people have problems playing .M3U8, it depends on the codecs used for the streaming and compatibility with the device, for example some of my .m3u8 files are only supported in devices with screens of 1200 x800 and higher.
You can use FFmpegMediaPlayer:
https://github.com/wseemann/FFmpegMediaPlayer
I also searched a lot to play m3u8 videos in Exo_player , if we use normal exo player to play m3u8 type videos it would not play for this. We need to do some changes , i did and it working fine for me.
In Kotlin :
private var exoPlayer: ExoPlayer? = null
private val playbackStateListener: Player.Listener = playbackStateListener()
private var currentItem = 0
private var playbackPosition = 0L
var url = ""
//Call this method from onStart() of the Activity.
private fun initializePlayer() {
exoPlayer = ExoPlayer.Builder(this).build()
videoView.player = exoPlayer
videoView.setKeepContentOnPlayerReset(true)
var mediaItem = MediaItem.Builder().
setUri("YOUR m3u8 url to play video ")
.setMimeType(MimeTypes.APPLICATION_M3U8).build()
exoPlayer?.let { exoPlayer ->
exoPlayer.setMediaItem(mediaItem)
exoPlayer.playWhenReady = true
exoPlayer.seekTo(currentItem, 20L)
exoPlayer.prepare()
}
}
Now You need to add dependency , do not forget to add dependency in gradle:
implementation 'com.google.android.exoplayer:exoplayer-hls:2.17.1'
Now for your easyness i will show the xml.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_height="match_parent">
<com.google.android.exoplayer2.ui.StyledPlayerView
android:id="#+id/videoView"
app:show_buffering="always"
app:resize_mode="fit"
app:keep_content_on_player_reset="false"
app:use_controller="true"
android:layout_width="match_parent"
android:layout_height="480dp" >
</com.google.android.exoplayer2.ui.StyledPlayerView>
</LinearLayout>

Play Mp4 video from server android

I want to play video of mp4 format and size 4-5Mb from server in streaming mode.I am using sdk version 2.3,on emulator it
gives only sound but not any picture.
I also tested it on devices Samsung(android sdk ver 2.1) and LG optimus(android sdk ver 2.2)
and only get "cannot play video:sorry this video is not valid for streaming to this device" message.
I have searched on this but not getting any solution, if anybody have any solution please help me.Thanks in advance.
Here is my code:
public class ShowVideo extends Activity
{
private static ProgressDialog progressDialog;
public String video_url;
private MediaController mediaController;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.videoalbum);
progressDialog = ProgressDialog.show(ShowVideo.this, "", "Buffering video...", true);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
video_url = "http://www.letumobi.com/videouploads/cd0a4170-1fb2-4fba-b17c-b5d70b2cd2e7.mp4";
try {
final VideoView videoView =(VideoView)findViewById(R.id.video_viewId);
mediaController = new MediaController(ShowVideo.this);
mediaController.setAnchorView(videoView);
// Set video link (mp4 format )
Uri video = Uri.parse(video_url);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
progressDialog.dismiss();
videoView.start();
}
});
}catch(Exception e){
progressDialog.dismiss();
System.out.println("Video Play Error :"+e.getMessage());
}
}
You may try these urls (ends with .3gp):
http://daily3gp.com/vids/747.3gp
http://daily3gp/www/vids/juggling_while_on_unicycle.3gp
instead of .mp4 urls:
video_url = "http://www.letumobi.com/videouploads/cd0a4170-1fb2-4fba-b17c-b5d70b2cd2e7.mp4";
On emulator it is difficult to get video played, because it needs really fast computer. Try this link for emulator. Maybe you can get some discrete video view.
http://commonsware.com/misc/test2.3gp
Also in your real devices this link should work if your implementation is proper.
I assume your video using following link
"http://www.letumobi.com/videouploads/cd0a4170-1fb2-4fba-b17c-b5d70b2cd2e7.mp4
is not proper for safe streaming.
You should hint that video or play other hinted videos. I couldn't find any other solution for playing unhinted videos yet.
This link may help.
getting PVMFErrContentInvalidForProgressivePlayback error while playing mp4 files on samsung devices

Categories

Resources