- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在我的服务器中创建了一个 XML 文件。它包含 title
和 link
标签。我获取标签并将它们显示为 ListView
中的链接。当用户点击链接时,我想在 Radio Station 应用程序中播放 .pls
文件。
这是我的 XML 文件:
<item>
<title> Kushi FM </title>
<link>http://108.163.197.114:8071/listen.pls</link>
</item>
我不知道如何在下一个 Activity 中播放链接。
主 Activity
:
public class MainActivity extends AppCompatActivity {
// All static variables
static final String URL1 = "http://servernmae.com/stations";
// XML node keys
static final String KEY_ITEM = "item"; // parent node
static final String KEY_TITLE = "title";
static final String KEY_LINK = "link";
URL url;
URLConnection urlConnection;
//Context context;
ListView listview;
int images=R.drawable.radio;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// isNetworkAvailable(this);
listview = (ListView) findViewById(R.id.list);
if(isNetworkAvailable(this))
{
new GetData().execute();
}else {
Toast.makeText(getApplicationContext(), "Please Connect to Internet and Check Again ! Thanks)",
Toast.LENGTH_LONG).show();
}
}
private boolean isNetworkAvailable(Context context) {
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
Log.w("INTERNET:",String.valueOf(i));
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
Log.w("INTERNET:", "connected!");
return true;
}
}
}
}
return false;
}
class GetData extends AsyncTask<String, String, String> {
String xml = "error";
@Override
protected String doInBackground(String... params) {
try {
url = new URL(URL1);
urlConnection = (HttpURLConnection) url.openConnection();
InputStream in = urlConnection.getInputStream();
InputStreamReader isw = new InputStreamReader(in);
BufferedReader br = new BufferedReader(isw);
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line + "\n");
}
br.close();
xml = sb.toString();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return xml;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
final ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
ArrayList<String> title= new ArrayList<>();
//title.add("");
Document doc = null;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder db = dbf.newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(xml));
doc = db.parse(is);
NodeList nl = doc.getElementsByTagName(KEY_ITEM);
for (int i = 0; i < nl.getLength(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
Log.e("TAg1", getValue(e, KEY_TITLE));
//Log.e("TAg2", getValue(e, KEY_LINK));
map.put(KEY_TITLE, getValue(e, KEY_TITLE));
map.put(KEY_LINK, getValue(e, KEY_LINK));
menuItems.add(map);
title.add(getValue(e, KEY_TITLE));
}
} catch (ParserConfigurationException e) {
Log.e("Error: ", e.getMessage());
} catch (SAXException e) {
Log.e("Error: ", e.getMessage());
} catch (IOException e) {
Log.e("Error: ", e.getMessage());
}
String[] dataArr = new String[title.size()];
dataArr = title.toArray(dataArr );
CustomAdapter adapter = new CustomAdapter(getApplicationContext(), dataArr );
listview.setAdapter(adapter);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//HashMap<String, String> selectedMap = menuItems.get(position);
HashMap<String,String> selectedMap= menuItems.get(position);
String urls = selectedMap.get(KEY_LINK);
Intent intent = new Intent(MainActivity.this, Service_Player.class);
intent.putExtra("url",urls);
startActivity(intent);
}
});
}
public final String getElementValue(Node elem) {
Node child;
if (elem != null) {
if (elem.hasChildNodes()) {
for (child = elem.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child.getNodeType() == Node.TEXT_NODE) {
return child.getNodeValue();
}
}
}
}
return "";
}
public String getValue(Element item, String str) {
NodeList n = item.getElementsByTagName(str);
return this.getElementValue(n.item(0));
}
}
Service_player.java
public class Service_Player extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_service__player);
startService(new Intent(this, MediaPlayerService.class));
String url = getIntent().getStringExtra("url");
if (!TextUtils.isEmpty(url))
startMediaPlayer(url);
}
@Override
protected void onResume() {
super.onResume();
registerReceiver(receiverFromservice, new IntentFilter(MediaPlayerService.SERVICE_TO_ACTIVITY));
}
private String currentPlayerStatus = "N/A";
private BroadcastReceiver receiverFromservice = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (MediaPlayerService.SERVICE_TO_ACTIVITY.equalsIgnoreCase(action)) {
/*
* To get current status of player
* */
currentPlayerStatus = intent.getStringExtra(MediaPlayerService.PLAYER_STATUS_KEY);
Log.e("Player Mode", "" + currentPlayerStatus);
}
}
};
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(receiverFromservice);
}
public void startMediaPlayer(String url) {
Intent intent = new Intent();
intent.setAction(MediaPlayerService.BROADCAST_TO_SERVICE);
intent.putExtra(MediaPlayerService.PLAYER_FUNCTION_TYPE, MediaPlayerService.PLAY_MEDIA_PLAYER);
intent.putExtra(MediaPlayerService.PLAYER_TRACK_URL, url);
sendBroadcast(intent);
}
媒体播放器服务.java
public class MediaPlayerService extends Service {
public static final String BROADCAST_TO_SERVICE = "com.mediaplayer.playerfunction";
public static final String SERVICE_TO_ACTIVITY = "com.mediaplayer.currentPlayerStatus";
public static final String PLAYER_FUNCTION_TYPE = "playerfunction";
public static final String PLAYER_TRACK_URL = "trackURL";
public static final int PLAY_MEDIA_PLAYER = 1;
public static final int PAUSE_MEDIA_PLAYER = 2;
public static final int RESUME_MEDIA_PLAYER = 3;
public static final int STOP_MEDIA_PLAYER = 4;
public static final int CHANGE_PLAYER_TRACK = 5;
public static final String PLAYER_STATUS_KEY = "PlayerCurrentStatus";
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
IntentFilter intentFilter = new IntentFilter(BROADCAST_TO_SERVICE);
registerReceiver(playerReceiver, intentFilter);
if (mPlayer != null && mPlayer.isPlaying()) {
sendPlayerStatus("playing");
}
return START_STICKY;
}
private BroadcastReceiver playerReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BROADCAST_TO_SERVICE.equalsIgnoreCase(action)) {
String trackURL = intent.hasExtra(PLAYER_TRACK_URL) ? intent.getStringExtra(PLAYER_TRACK_URL) : "";
int function = intent.getIntExtra(PLAYER_FUNCTION_TYPE, 0);
switch (function) {
case CHANGE_PLAYER_TRACK:
changeTrack(trackURL);
break;
case STOP_MEDIA_PLAYER:
stopPlayer();
break;
case PLAY_MEDIA_PLAYER:
startMediaPlayer(trackURL);
break;
case PAUSE_MEDIA_PLAYER:
pausePlayer();
break;
case RESUME_MEDIA_PLAYER:
resumePlayer();
break;
}
}
}
};
private MediaPlayer mPlayer;
private void pausePlayer() {
if (mPlayer != null && mPlayer.isPlaying()) {
mPlayer.pause();
sendPlayerStatus("pause");
}
}
private void resumePlayer() {
if (mPlayer != null && !mPlayer.isPlaying()) {
mPlayer.start();
sendPlayerStatus("playing");
}
}
private void changeTrack(String url) {
stopPlayer();
startMediaPlayer(url);
}
private void stopPlayer() {
if (mPlayer != null) {
mPlayer.stop();
mPlayer.release();
mPlayer = null;
sendPlayerStatus("stopped");
}
}
public void startMediaPlayer(String url) {
if (TextUtils.isEmpty(url))
return;
if (mPlayer == null)
mPlayer = new MediaPlayer();
try {
mPlayer.setDataSource(url);
mPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
if (extra == MediaPlayer.MEDIA_ERROR_SERVER_DIED
|| extra == MediaPlayer.MEDIA_ERROR_MALFORMED) {
sendPlayerStatus("erroronplaying");
} else if (extra == MediaPlayer.MEDIA_ERROR_IO) {
sendPlayerStatus("erroronplaying");
return false;
}
return false;
}
});
mPlayer.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
public void onBufferingUpdate(MediaPlayer mp, int percent) {
Log.e("onBufferingUpdate", "" + percent);
}
});
mPlayer.prepareAsync();
mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mPlayer.start();
sendPlayerStatus("playing");
}
});
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
Log.e("onCompletion", "Yes");
sendPlayerStatus("completed");
}
});
mPlayer.setOnInfoListener(new MediaPlayer.OnInfoListener() {
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
return false;
}
});
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private void sendPlayerStatus(String status) {
Intent intent = new Intent();
intent.setAction(SERVICE_TO_ACTIVITY);
intent.putExtra(PLAYER_STATUS_KEY, status);
sendBroadcast(intent);
}
list .xml
<!-- Internet Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Network State Permissions -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Service_Player"
android:label="@string/title_activity_service__player" >
</activity>
<service android:name=".MediaPlayerService"></service>
</application>
最佳答案
我建议您使用 Service 如果您正在使用 MediaPlayer 流式传输或普通 MediaPlayer 创建应用程序。可以很容易地集中处理播放器背景。
要在服务中使用媒体播放器,您可以将其与 BroadCastReceiver 一起使用 或根据您的要求绑定(bind)服务。如果您保留 MediaPlayer 相关服务,那将是很好的 running in foreground 下面的代码我没有处理,请检查给定的链接。
在示例代码中,我使用 BroadCast Receiver 将命令从 Activity 发送到 MediaPlayer 服务(如播放、暂停、更改轨道等),反之亦然。
现在要获取您从 Activity onItemClickListner 发送的 url,您需要从 Intent 获取。
String url = getIntent().getStringExtra("url");
播放器屏幕
public class PlayerScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.player);
startService(new Intent(this, MediaPlayerService.class));
findViewById(R.id.btnChangeTrack).setOnClickListener(clickListener);
findViewById(R.id.btnStartMediaPlayer).setOnClickListener(clickListener);
findViewById(R.id.btnStopMediaPlayer).setOnClickListener(clickListener);
ToggleButton toggleButton = (ToggleButton) findViewById(R.id.togglePauseResume);
toggleButton.setOnCheckedChangeListener(checkedChangeListener);
/*
* To get url which is passing from the previous activity listitem click.
* If url which is pass from listitem click is not empty it will start player
* */
String url = getIntent().getStringExtra("url");
if (!TextUtils.isEmpty(url))
startMediaPlayer(url);
}
private ToggleButton.OnCheckedChangeListener checkedChangeListener = new ToggleButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (!isChecked) {
Intent intent = new Intent();
intent.setAction(MediaPlayerService.BROADCAST_TO_SERVICE);
intent.putExtra(MediaPlayerService.PLAYER_FUNCTION_TYPE, MediaPlayerService.PAUSE_MEDIA_PLAYER);
sendBroadcast(intent);
} else {
Intent intent = new Intent();
intent.setAction(MediaPlayerService.BROADCAST_TO_SERVICE);
intent.putExtra(MediaPlayerService.PLAYER_FUNCTION_TYPE, MediaPlayerService.RESUME_MEDIA_PLAYER);
sendBroadcast(intent);
}
}
};
private View.OnClickListener clickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent;
switch (v.getId()) {
case R.id.btnChangeTrack:
intent = new Intent();
intent.setAction(MediaPlayerService.BROADCAST_TO_SERVICE);
intent.putExtra(MediaPlayerService.PLAYER_FUNCTION_TYPE, MediaPlayerService.CHANGE_PLAYER_TRACK);
intent.putExtra(MediaPlayerService.PLAYER_TRACK_URL, "http://69.64.41.64:9938");
sendBroadcast(intent);
break;
case R.id.btnStartMediaPlayer:
startMediaPlayer("http://108.163.197.114:8071/listen.pls");
break;
case R.id.btnStopMediaPlayer:
intent = new Intent();
intent.setAction(MediaPlayerService.BROADCAST_TO_SERVICE);
intent.putExtra(MediaPlayerService.PLAYER_FUNCTION_TYPE, MediaPlayerService.STOP_MEDIA_PLAYER);
sendBroadcast(intent);
break;
}
}
};
@Override
protected void onResume() {
super.onResume();
registerReceiver(receiverFromservice, new IntentFilter(MediaPlayerService.SERVICE_TO_ACTIVITY));
}
private String currentPlayerStatus = "N/A";
private BroadcastReceiver receiverFromservice = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (MediaPlayerService.SERVICE_TO_ACTIVITY.equalsIgnoreCase(action)) {
/*
* To get current status of player
* */
currentPlayerStatus = intent.getStringExtra(MediaPlayerService.PLAYER_STATUS_KEY);
Log.e("Player Mode", "" + currentPlayerStatus);
}
}
};
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(receiverFromservice);
}
/**
* TO start media player.It will send broadcast to Service & from service player will start
*
* @param url
*/
public void startMediaPlayer(String url) {
Intent intent = new Intent();
intent.setAction(MediaPlayerService.BROADCAST_TO_SERVICE);
intent.putExtra(MediaPlayerService.PLAYER_FUNCTION_TYPE, MediaPlayerService.PLAY_MEDIA_PLAYER);
intent.putExtra(MediaPlayerService.PLAYER_TRACK_URL, url);
sendBroadcast(intent);
}
}
媒体播放服务
public class MediaPlayerService extends Service {
public static final String BROADCAST_TO_SERVICE = "com.mediaplayer.playerfunction";
public static final String SERVICE_TO_ACTIVITY = "com.mediaplayer.currentPlayerStatus";
public static final String PLAYER_FUNCTION_TYPE = "playerfunction";
public static final String PLAYER_TRACK_URL = "trackURL";
public static final int PLAY_MEDIA_PLAYER = 1;
public static final int PAUSE_MEDIA_PLAYER = 2;
public static final int RESUME_MEDIA_PLAYER = 3;
public static final int STOP_MEDIA_PLAYER = 4;
public static final int CHANGE_PLAYER_TRACK = 5;
public static final String PLAYER_STATUS_KEY = "PlayerCurrentStatus";
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
IntentFilter intentFilter = new IntentFilter(BROADCAST_TO_SERVICE);
registerReceiver(playerReceiver, intentFilter);
if (mPlayer != null && mPlayer.isPlaying()) {
sendPlayerStatus("playing");
}
return START_STICKY;
}
private BroadcastReceiver playerReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (BROADCAST_TO_SERVICE.equalsIgnoreCase(action)) {
String trackURL = intent.hasExtra(PLAYER_TRACK_URL) ? intent.getStringExtra(PLAYER_TRACK_URL) : "";
int function = intent.getIntExtra(PLAYER_FUNCTION_TYPE, 0);
switch (function) {
case CHANGE_PLAYER_TRACK:
changeTrack(trackURL);
break;
case STOP_MEDIA_PLAYER:
stopPlayer();
break;
case PLAY_MEDIA_PLAYER:
startMediaPlayer(trackURL);
break;
case PAUSE_MEDIA_PLAYER:
pausePlayer();
break;
case RESUME_MEDIA_PLAYER:
resumePlayer();
break;
}
}
}
};
private MediaPlayer mPlayer;
private void pausePlayer() {
if (mPlayer != null && mPlayer.isPlaying()) {
mPlayer.pause();
sendPlayerStatus("pause");
}
}
private void resumePlayer() {
if (mPlayer != null && !mPlayer.isPlaying()) {
mPlayer.start();
sendPlayerStatus("playing");
}
}
private void changeTrack(String url) {
stopPlayer();
startMediaPlayer(url);
}
private void stopPlayer() {
if (mPlayer != null) {
mPlayer.stop();
mPlayer.release();
mPlayer = null;
sendPlayerStatus("stopped");
}
}
public void startMediaPlayer(String url) {
if (TextUtils.isEmpty(url))
return;
if (mPlayer == null)
mPlayer = new MediaPlayer();
try {
mPlayer.setDataSource(url);
mPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
if (extra == MediaPlayer.MEDIA_ERROR_SERVER_DIED
|| extra == MediaPlayer.MEDIA_ERROR_MALFORMED) {
sendPlayerStatus("erroronplaying");
} else if (extra == MediaPlayer.MEDIA_ERROR_IO) {
sendPlayerStatus("erroronplaying");
return false;
}
return false;
}
});
mPlayer.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
public void onBufferingUpdate(MediaPlayer mp, int percent) {
Log.e("onBufferingUpdate", "" + percent);
}
});
mPlayer.prepareAsync();
mPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mPlayer.start();
sendPlayerStatus("playing");
}
});
mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
Log.e("onCompletion", "Yes");
sendPlayerStatus("completed");
}
});
mPlayer.setOnInfoListener(new MediaPlayer.OnInfoListener() {
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
return false;
}
});
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private void sendPlayerStatus(String status) {
Intent intent = new Intent();
intent.setAction(SERVICE_TO_ACTIVITY);
intent.putExtra(PLAYER_STATUS_KEY, status);
sendBroadcast(intent);
}
}
player.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/ab_tool"
android:text="Home" />
<Button
android:id="@+id/btnStartMediaPlayer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/section_label"
android:text="Start Player" />
<ToggleButton
android:id="@+id/togglePauseResume"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btnStartMediaPlayer"
android:checked="true"
android:textOff="Resume"
android:textOn="Pause" />
<Button
android:id="@+id/btnChangeTrack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/togglePauseResume"
android:text="Chanage Track" />
<Button
android:id="@+id/btnStopMediaPlayer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/btnChangeTrack"
android:text="STOP" />
</RelativeLayout>
list
<activity android:name=".PlayerScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".MediaPlayerService"></service>
要从流式 url header 数据中获取数据,您可以 check this answer
为了测试目的,我在这里使用了两个 url
更新播放器 Activity
public class PlayerScreen extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.player);
startService(new Intent(this, MediaPlayerService.class));
/*
* To get url which is passing from the previous activity listitem click.
* If url which is pass from listitem click is not empty it will start player
* */
String url = getIntent().getStringExtra("url");
if (!TextUtils.isEmpty(url))
startMediaPlayer(url);
}
@Override
protected void onResume() {
super.onResume();
registerReceiver(receiverFromservice, new IntentFilter(MediaPlayerService.SERVICE_TO_ACTIVITY));
}
private String currentPlayerStatus = "N/A";
private BroadcastReceiver receiverFromservice = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (MediaPlayerService.SERVICE_TO_ACTIVITY.equalsIgnoreCase(action)) {
/*
* To get current status of player
* */
currentPlayerStatus = intent.getStringExtra(MediaPlayerService.PLAYER_STATUS_KEY);
Log.e("Player Mode", "" + currentPlayerStatus);
}
}
};
@Override
protected void onPause() {
super.onPause();
unregisterReceiver(receiverFromservice);
}
/**
* TO start media player.It will send broadcast to Service & from service player will start
*
* @param url
*/
public void startMediaPlayer(String url) {
Intent intent = new Intent();
intent.setAction(MediaPlayerService.BROADCAST_TO_SERVICE);
intent.putExtra(MediaPlayerService.PLAYER_FUNCTION_TYPE, MediaPlayerService.PLAY_MEDIA_PLAYER);
intent.putExtra(MediaPlayerService.PLAYER_TRACK_URL, url);
sendBroadcast(intent);
}
}
如果有什么事请告诉我。
关于android - 如何在 Android 中播放在线广播流媒体 url。如何在 android 中播放 .pls 广播流媒体 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34945645/
我做了一个项目,使用两个不同的textview进行触摸来播放两个音频。 这是一个文本 View 的简单代码 tv.setOnTouchListener(new OnTouchListener() {
我正在使用 pygame 模块在 python 中操作声音文件。它在交互式 python session 中工作正常,但相同的代码在 bash 中不会产生任何结果: 交互式Python $ sudo
请注意它只能是 JavaScript。请参阅下面我当前的 HTML。我需要像当前代码一样在页面之间旋转。但是,我需要能够在页面之间暂停/播放。
我有一个带有一堆音频链接的html。我正在尝试使所有音频链接都在单击时播放/暂停,并且尝试了here解决方案。这正是我所追求的,只是我现在不得不修改此功能以应用于代码中的所有音频链接(因为我不能为每个
在尝试进入我的代码中的下一个文件之前,我尝试随机播放.wav文件数毫秒。最好的方法是什么? 我目前有以下代码: #!/usr/bin/env python from random import ran
我有2个回调函数,一个播放音频,另一个停止音频。 function Play_Callback(hObject, eventdata, handles) global path; global pla
我有一个电台应用程序,并与carplay集成。在Carplay仪表板中,我仅看到专辑封面图像和停止按钮。我想在仪表板上显示播放/暂停和跳过按钮。如果您对该站有任何了解,可以帮我吗? 最佳答案 您需要使
我正在使用 ffmpeg 创建一个非常基本的视频播放器。库,我有所有的解码和重新编码,但我坚持音频视频同步。 我的问题是,电影有音频和视频流混合(交织),音频和视频以“突发”(多个音频包,然后是并列的
我不知道我在做什么错 $(document).ready(function() { var playing = false; var audioElement = document.
我正在尝试通过(input:file)Elem加载本地音频文件,当我将其作为对象传递给音频构造函数Audio()时,它不会加载/播放。 文件对象参数和方法: lastModified: 1586969
在 Qt 中创建播放/暂停按钮的最佳方法是什么?我应该创建一个操作并在单击时更改其图标,还是应该创建两个操作然后以某种方式在单击时隐藏一个操作?如何使用一个快捷键来激活这两个操作? (播放时暂停,暂停
我正在用 Python 和 SQLite 构建一个预订系统。 我有一个 Staff.db 和 Play.db (一对多关系)。这个想法是这样的:剧院的唯一工作人员可以通过指定开始日期和时间来选择何时添
我有一个服务于 AAC+ (HE v2) 的 Icecast 服务器。我在我的网页中使用 JPlayer 来播放内容。在没有 Flash Player 的 Chromium 中,它工作得很好。 对于支
当我运行我的方法时,我收到一个MediaException。我使用 playSound("src/assets/timeup.mp3"); 调用该方法。 private void playSound(
我有一项正在播放播客的服务。我希望该服务检测用户何时按下暂停或从他们的 BT radio 播放,以便我可以停止和启动它。对于我的生活,我无法弄清楚要向我的监听器添加什么过滤器(当我按下 BT 按钮时,
我对 Java 不是很在行,在研究网站上的音乐循环的简单播放/暂停按钮后,我得到了这段代码。它可以很好地离线测试,但在上传到 FTP 服务器后,它不会在任何浏览器中播放音频,我得到 SyntaxErr
我有一个使用 flickity carousel library 创建的视频轮播, 见过 here on codepen .我想要发生的是,当用户滑动轮播时,所选幻灯片停止播放,然后占据所选中间位置的
这是一个 JSFiddle: http://jsfiddle.net/8LczkwLz/19/ HTML: JS: var flashcardAudio = documen
我的问题是我无法将歌曲标题文本保持在 line-height: 800px;当用户播放或暂停播放器时。我设法在 :hover 上做到了。这似乎是一件非常棘手的事情,这真的是我第一次遇到 CSS 如此困
我还没有找到与我的完全一样的帖子,所以这就是问题所在。我正在制作一个 mp3 播放器,播放/暂停是两个单独的按钮。这是我的代码。 prevButton = document.getElementByI
我是一名优秀的程序员,十分优秀!