- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Android 平台的应用程序开发人员。现在我希望当应用程序开始自动播放流媒体中的音乐时,不幸的是,我不能这样做,我有一个条件,检查背景是否有音乐,但这不起作用,因为应用程序开始流式传输音乐,但当我想停止它时,它会启动音乐和流式传输双重。
playStop = findViewById(R.id.playStopBtn);
nowPlaying = findViewById(R.id.radioStationNowPlaying);
nowPlaying.setTypeface(dorcic);
setIsPlaying(false);
processPhoneListenerPermission();
broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Service.TELEPHONY_SERVICE);
if (tm != null) {
if (tm.getCallState() == TelephonyManager.CALL_STATE_RINGING) {
if (getIsPlaying()) {
stop();
}
}
}
}
};
IntentFilter filter = new IntentFilter();
filter.addAction("android.intent.action.PHONE_STATE");
registerReceiver(broadcastReceiver, filter);
loadNowPlaying();
playStop.setOnClickListener(view -> {
if (isNetworkAvailable()) {
if (getIsPlaying()) {
stop();
} else {
play();
}
} else {
Toast.makeText(getApplicationContext(), "No internet", Toast.LENGTH_LONG).show();
}
});
}
private void loadNowPlaying() {
Thread t = new Thread() {
public void run() {
try {
while (!isInterrupted()) {
runOnUiThread(() -> reloadShoutCastInfo());
Thread.sleep(20000);
}
} catch (InterruptedException ignored) {
}
}
};
t.start();
}
private void reloadShoutCastInfo() {
if (isNetworkAvailable()) {
AsyncTaskRunner runner = new AsyncTaskRunner();
runner.execute();
}
}
@SuppressLint("StaticFieldLeak")
private class AsyncTaskRunner extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... params) {
FFmpegMediaMetadataRetriever mmr = new FFmpegMediaMetadataRetriever();
mmr.setDataSource(STREAMING_URL);
nowPlayingData = mmr.extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_ICY_METADATA).replaceAll("StreamTitle", "").replaceAll("[=,';]+", "");
mmr.release();
return null;
}
@Override
protected void onPostExecute(String result) {
nowPlaying.setText(nowPlayingData);
}
}
private void processPhoneListenerPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE}, 121);
}
}
public boolean isNetworkAvailable() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = null;
if (cm != null) {
networkInfo = cm.getActiveNetworkInfo();
}
return networkInfo != null && networkInfo.isConnectedOrConnecting();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == 121) {
if (!(grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
Toast.makeText(getApplicationContext(), "Permission not granted.\nWe can't pause music when phone ringing.", Toast.LENGTH_LONG).show();
}
}
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
@Override
public void onBackPressed()
{
Toast.makeText(MainActivity.this,"לחצו על כפתור הבית לשמיעת הרדיו ברקע", Toast.LENGTH_LONG).show();
}
private void setIsPlaying(boolean status) {
SharedPreferences.Editor editor = getApplicationContext().getSharedPreferences("isPlaying", MODE_PRIVATE).edit();
editor.putBoolean("isPlaying", status);
editor.apply();
}
private boolean getIsPlaying() {
SharedPreferences prefs = getApplicationContext().getSharedPreferences("isPlaying", MODE_PRIVATE);
return prefs.getBoolean("isPlaying", false);
}
private void play() {
setIsPlaying(true);
Intent servicePlayIntent = new Intent(this, MyService.class);
servicePlayIntent.putExtra("playStop", "play");
startService(servicePlayIntent);
playStop.setImageResource(R.drawable.ic_pause);
Toast.makeText(getApplicationContext(), "מתנגן...", Toast.LENGTH_LONG).show();
}
private void stop() {
setIsPlaying(false);
Intent serviceStopIntent = new Intent(this, MyService.class);
serviceStopIntent.putExtra("playStop", "stop");
startService(serviceStopIntent);
playStop.setImageResource(R.drawable.ic_play);
Toast.makeText(getApplicationContext(), "עוצר...", Toast.LENGTH_LONG).show();
}
@Override
protected void onStop() {
super.onStop();
}
@Override
protected void onStart() {
play();
super.onStart();
}
@Override
protected void onDestroy() {
stopService(new Intent(getApplicationContext(), MyService.class));
unregisterReceiver(broadcastReceiver);
finish();
super.onDestroy();
}
}
最佳答案
尝试定义这个:
线程t = new Thread()
作为整个类的变量,而不仅仅是内部方法
这样就可以了
关于java - 无法播放流媒体onstart方法android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61523256/
我正在使用 Twitter4j 流 API。我正在使用地理定位约束来仅从特定区域获取推文。这是代码的那部分: twitterStream.addListener(listener);
我正在使用 WCF 并希望将大文件从客户端上传到服务器。我已经调查并决定遵循 http://msdn.microsoft.com/en-us/library/aa717050.aspx 中概述的分块方
我和提问者的情况很相似: Can I serve MP3 files with PHP?基本上我试图保护 mp3 文件不被直接下载,因此用户必须首先通过 php 进行身份验证。这是我的代码: head
我连接了 Red5 oflaDemo 并且工作正常 当我尝试使用 ffmpeg rtmp 流式传输 flv 文件时,我遇到了这个错误 root@zzz-OptiPlex-170L:~# ffmpeg
我正在尝试压缩一堆文件并通过流使数据可用。 我希望内存占用尽可能小。 我的想法是实现一个 Stream,其中我有一堆 FileStream 对象作为数据成员。当我的 Stream 上的 Read 方法
只是想知道是否有人知道自动执行此操作和/或作为 50 mp4 视频的批处理的脚本或程序。我说的是使用 CLI mediafilesegmenter 命令将视频分段的过程,以便从 Amazon S3 流
我有一个带有摄像头模块的 Raspberry Pi,我想将 PiCamera 的视频返回从 Python 流式传输到另一台运行 Python 服务器的计算机。 我成功地使用 OpenCV 返回了视频(
我正在使用 ffmpeg sdk 在 youtube live 上流式传输实时视频 av_interleaved_write_frame(m_pAvFmtCntx, pkt); av_interlea
我正在尝试使用 Tweepy 流式传输 Twitter,我想知道是否可以在不提供关键字的情况下进行流式传输?因此,我将能够流式传输所有推文,而不仅仅是具有给定关键字的推文。我正在关注的代码可以在这里找
我是 Hazelcast 的新手,我正在尝试使用它来将数据存储在太大而无法容纳在单台计算机上的 map 中。 我需要实现的过程之一是检查 map 中的每个值并对其执行某些操作 - 不是累积或聚合,而且
我需要设置从多个网络摄像头到互联网(在浏览器中)的实时流传输,并且这些流应该仅对特定用户可见。 IE。用户 A 使用他或她的登录名/密码登录我的系统,转到视频流页面,并查看来自特定摄像头的流,而其他用
我在看 Twitter Streaming API获取实时提要。但我不希望它存储在我的服务器上。我只是希望它从服务器中提取,浏览器页面将从我的服务器的 twitter 提取 URL 检索数据。但我想避
我想创建一个P2P视频传输的应用程序。更详细地说,我需要以下内容: 用户可以通过点击应用程序中的按钮来打开网络摄像头。 应用程序开始从网络摄像头拍摄图像并将其发送到特定位置(由端口和 IP 地址指定)
我们有一个在 Tomcat 下运行的 Java Web 应用程序(应用程序 #1)。 我们的要求:我们想为流媒体设置一个单独的服务器。我们的媒体文件已经转换为 flv(我们支持的唯一格式)...我们只
我是 RTMP 流媒体的新手,正在寻求帮助。足以让我开始。 我已经在谷歌上搜索了大约 5-7 个小时,但仍然无法确定我的答案! Red5的文档有限,根本找不到任何支持!甚至与我类似的问题在 stack
我正在尝试编写一个简单的 map only hadoop streaming job 从 hdfs 读取数据并将其推送到 vertica。 我写了几个shell脚本如下 加载.sh hadoop
我是 Android 的新手,正在尝试: 从相机流式传输原始数据 (ImageFormat RAW_SENSOR) 处理原始数据 交互显示处理结果 原始数据捕获似乎只能在静态捕获模式下使用。这是正确的
我需要将音频从麦克风流式传输到 http 服务器。 这些录音设置是我需要的: NSDictionary *audioOutputSettings = [NSDictionary dictionaryW
我需要了解 WCF 在发送消息时是如何工作的。 WCF 在发送之前是否序列化所有内容? 我的另一个问题是使用 Streaming 有什么好处?更大的消息是否更好,比如说 1Mb 到 2Mb?我可以发送
是否可以直接从 API 初始化新的环聊直播广播/流式传输?我尝试将环聊直播用于我网站的直播系统,但我在 YouTube Live API 中没有看到任何允许通过环聊直播创建流的 API 方法(看起来需
我是一名优秀的程序员,十分优秀!