⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qmhttpstream.cpp

📁 可以播放MP3,wma等文件格式的播放器
💻 CPP
字号:
/* qmhttpstream.cpp * * $Id: qmhttpstream.cpp,v 1.2.2.1 2002/10/11 06:39:04 kyllingstad Exp $ * * Apollo sound player: http://www.apolloplayer.org * Copyright(C) 2000-2002 Apollo Team.  See CREDITS file. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. * * The GNU General Public License is also available online at: * * http://www.gnu.org/copyleft/gpl.html */#include "qmhttpstream.h"#include <iostream>#include <qsocket.h>#include <qtextstream.h>/*!  \class QmHttpStream qmhttpstream.h  \brief Provides functionality for reading audio from a web server.*//*!*/QmHttpStream::QmHttpStream(	const QString &url)	: m_Url(url),	  m_HttpRequest(1024){	m_pSocket = new QSocket;	connect(m_pSocket, SIGNAL(hostFound()), this, SLOT(hostFound()));	connect(m_pSocket, SIGNAL(connected()), this, SLOT(connected()));	connect(m_pSocket, SIGNAL(connectionClosed()), this, SLOT(connectionClosed()));	connect(m_pSocket, SIGNAL(readyRead()), this, SLOT(readyRead()));}/*!*/QmHttpStream::~QmHttpStream(){	delete m_pSocket;}/*!  Opens the URL given.  \return True if successful, false otherwise.  \sa setUrl(const QString&) */boolQmHttpStream::open(){	if( ! m_Url.isValid())		return false;	m_pSocket->connectToHost(m_Url.host(), m_Url.port());		return true;}/*!  Sets the URL to \a url.  If the URL is invalid, open() will fail.  \sa open() */voidQmHttpStream::setUrl(	const QString &url){	m_Url = url;}/*! */voidQmHttpStream::hostFound(){	std::cout << "Host " << m_Url.toString() << " found. Connecting..." << std::endl;}/*! */voidQmHttpStream::connected(){	std::cout << "Connected to " << m_Url.toString() << std::endl;	// The code below is based on network.c in mpg321 by Joe Drew.	char http_request[1024];	sprintf(http_request,			"GET /%s HTTP/1.0\r\n"			"User-Agent: Mozilla/2.0 (Win95; I)\r\n"			"Pragma: no-cache\r\n"			"Host: %s\r\n"			"Accept: */*\r\n"			"\r\n",			m_Url.fileName().latin1(), m_Url.host().latin1());//	m_pSocket->writeBlock(http_request, strlen(http_request));//	m_HttpRequest.fill('\0', m_HttpRequest.size());//	QTextStream str(m_HttpRequest);//	str << "GET /" << m_Url.fileName() << " HTTP/1.0\r\n"//		<< "User-Agent: Mozilla/2.0 (Win95; I)\r\n"//		<< "Pragma: no-cache\r\n"//		<< "Host: " << m_Url.host() << "\r\n"//		<< "Accept: */*\r\n"//		<< "\r\n";//	std::cout << m_HttpRequest.data();		/* Parse server reply */	/*	do read(tcp_sock, &c, sizeof(char)); while(c != ' ');	read(tcp_sock, http_request, 4*sizeof(char));	http_request[4] = 0;	if(strcmp(http_request, "200 "))	{		fprintf(stderr, "http_open: ");		do {			read(tcp_sock, &c, sizeof(char));			fprintf(stderr, "%c", c);		}		while(c != '\r');		fprintf(stderr, "\n");		return(0);	}	*/}/*! */voidQmHttpStream::connectionClosed(){	std::cout << "Connection to " << m_Url.toString() << " closed." << std::endl;}/*! */voidQmHttpStream::readyRead(){	std::cout << "Ready to read from " << m_Url.toString() << std::endl;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -